Part Number Hot Search : 
L6207N ON2501 473B3 E13005 TLHR4200 BU808DFP VSA64016 78L09
Product Description
Full Text Search
 

To Download PIC18F1230-IMLSQTP Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2006 microchip technology inc. advance information ds39758b pic18f1230/1330 data sheet 18/20/28-pin, enhanced flash microcontrollers with nanowatt technology, high-performance pwm and a/d
ds39758b-page ii advance information ? 2006 microchip technology inc. information contained in this publication regarding device applications and the like is provi ded only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application m eets with your specifications. microchip makes no representations or war- ranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , micro id , mplab, pic, picmicro, picstart, pro mate, powersmart, rfpic and smartshunt are registered trademarks of micr ochip technology incorporated in the u.s.a. and other countries. amplab, filterlab, migratable memory, mxdev, mxlab, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, app lication maestro, dspicdem, dspicdem.net, dspicworks, ecan, economonitor, fansense, flexrom, fuzzylab, in-circuit serial programming, icsp, icepic, linear active thermistor, mpasm, mplib, mplink, mpsim, pickit, picdem, picdem.net, piclab, pictail, powercal, powerinfo, powermate, powertool, real ice, rflab, rfpicdem, select mode, smart serial, smarttel, total endurance, uni/o, wiperlock and zena are trademarks of microchip technology incorporated in the u.s.a. and other countries. sqtp is a service mark of mi crochip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2006, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specif ications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 quality system certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona and mountain view, california in october 2003. the company?s quality system processes and procedures are for its picmicro ? 8-bit mcus, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2006 microchip technology inc. advance information ds39758b-page 1 14-bit power control pwm module: ? up to 6 pwm channel outputs - complementary or independent outputs ? edge or center-aligned operation ? flexible dead-band generator ? hardware fault protection input ? simultaneous update of duty cycle and period: - flexible special event trigger output flexible oscillator structure: ? four crystal modes, up to 40 mhz ? 4x phase lock loop (pll) ? available for crystal and internal oscillators ? two external rc modes, up to 4 mhz ? two external clock modes, up to 40 mhz ? internal oscillator block: - 8 user-selectable frequencies from 31 khz to 8 mhz - provides a complete range of clock speeds from 31 khz to 32 mhz when used with pll - user-tunable to compensate for frequency drift ? secondary oscillator using timer1 @ 32 khz ? fail-safe clock monitor: - allows for safe shutdown if peripheral clock stops power-managed modes: ? run: cpu on, peripherals on ? idle: cpu off, peripherals on ? sleep: cpu off, peripherals off ? idle mode currents down to 5.8 a, typical ? sleep mode current down to 0.1 a, typical ? timer1 oscillator: 1.8 a, typical; 32 khz; 2v ? watchdog timer (wdt): 2.1 a, typical ? two-speed oscillator start-up peripheral highlights: ? high-current sink/source 25 ma/25 ma ? up to 4 programmable external interrupts ? four input change interrupts ? enhanced addressable usart module: - supports rs-485, rs-232 and lin 1.2 - rs-232 operation using internal oscillator block (no external crystal required) - auto-wake-up on start bit - auto-baud detect ? 10-bit, up to 4-channel analog-to-digital converter module (a/d): - auto-acquisition capability - conversion available during sleep ? up to 3 analog comparators ? programmable reference voltage for comparators ? programmable 15-level low-voltage detection (lvd) module: - supports interrupt on low-voltage detection special microcontroller features: ? c compiler optimized architecture with optional extended instruction set ? flash memory retention: > 40 years ? self-programmable under software control ? priority levels for interrupts ? 8 x 8 single-cycle hardware multiplier ? extended watchdog timer (wdt): - programmable period from 4 ms to 131s ? programmable code protection ? single-supply in-circuit serial programming? (icsp?) via two pins ? in-circuit debug (icd) via two pins ? wide operating voltage range (2.0v to 5.5v) device program memory data memory i/o 10 - bit adc channel eusart analog comparator 14-bit pwm (ch) timers 16-bit flash (bytes) # single-word instructions sram (bytes) eeprom (bytes) pic18f1230 4096 2048 256 128 13 4 yes 3 6 2 pic18f1330 8192 4096 256 128 13 4 yes 3 6 2 18/20/28-pin, enhanced fl ash microcontrollers with nanowatt technology, high -performance pwm and a/d pic18f1230/1330
pic18f1230/1330 ds39758b-page 2 advance information ? 2006 microchip technology inc. pin diagrams 18-pin pdip, soic 2 3 4 5 6 1 8 7 9 ra0/an0/int0/kbi0/cmp0 ra1/an1/int1/kbi1 ra4/t0cki/an2/v ref + v ss /av ss ra2/tx/ck ra3/rx/dt rb0/pwm0 rb1/pwm1 pic18f1x30 17 16 15 14 13 18 11 12 10 rb3/int3/kbi3/cmp1/t1osi (1) ra7/osc1/clki/t1osi (1) /flta (2) ra6/osc2/clko/t1oso (1) /t1cki (1) /an3 v dd /av dd rb7/pwm5/pgd rb6/pwm4/pgc rb5/pwm3 rb4/pwm2 20-pin ssop note 1: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h. 2: placement of flta depends on the value of configuration bit, fltamx, of config3h. mclr /v pp /ra5/flta (2) 2 3 4 5 6 1 8 7 9 ra0/an0/int0/kbi0/cmp0 ra1/an1/int1/kbi1 ra4/t0cki/an2/v ref + v ss ra2/tx/ck ra3/rx/dt rb0/pwm0 rb1/pwm1 pic18f1x30 19 18 17 16 15 20 13 14 12 rb3/int3/kbi3/cmp1/t1osi (1) ra7/osc1/clki/t1osi (1) /flta (2) v dd rb7/pwm5/pgd rb6/pwm4/pgc rb5/pwm3 rb4/pwm2 mclr /v pp /ra5/flta (2) 10 11 av ss av dd rb2/int2/kbi2cmp2/t1oso (1) /t1cki (1) ra6/osc2/clko/t1oso (1) /t1cki (1) /an3 rb2/int2/kbi2cmp2/t1oso (1) /t1cki (1)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 3 pin diagrams (continued) 28-pin qfn (3) note 1: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h. 2: placement of flta depends on the value of configuration bit, fltamx, of config3h. 3: it is recommended that the user connect the center metal pad for this device package to the ground. 10 11 2 3 6 1 18 19 20 21 22 12 13 14 15 8 7 16 17 23 24 25 26 27 28 9 pic18f1x30 ra3/rx/dt 5 4 nc rb3/int3/kbi3/cmp1/t1osi (1) nc ra7/osc1/clki/t1osi (1) /flta (2) v dd nc av dd rb7/pwm5/pgd rb6/pwm4/pgc nc rb5/pwm3 rb4/pwm2 ra0/an0/int0/kbi0/cmp0 ra1/an1/int1/kbi1 ra4/t0cki/an2/v ref + mclr /v pp /ra5/flta (2) nc v ss nc av ss nc ra2/tx/ck rb0/pwm0 rb1/pwm1 nc rb2/int2/kbi2cmp2/t1oso (1) /t1cki (1) ra6/osc2/clko/t1oso (1) /t1cki (1) /an3
pic18f1230/1330 ds39758b-page 4 advance information ? 2006 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 7 2.0 oscillator configurations ................................................................................................... ......................................................... 15 3.0 power-managed modes ......................................................................................................... .................................................... 25 4.0 reset ....................................................................................................................... ................................................................... 33 5.0 memory organization ......................................................................................................... ........................................................ 45 6.0 flash program memory........................................................................................................ ...................................................... 65 7.0 data eeprom memory .......................................................................................................... ................................................... 75 8.0 8 x 8 hardware multiplier................................................................................................... ......................................................... 79 9.0 i/o ports ................................................................................................................... .................................................................. 81 10.0 interrupts ................................................................................................................. ................................................................... 87 11.0 timer0 module .............................................................................................................. ........................................................... 101 12.0 timer1 module .............................................................................................................. ........................................................... 105 13.0 power control pwm module ................................................................................................... ................................................. 111 14.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) .................................................. ............. 141 15.0 10-bit analog-to-digital converter (a/d) module ............................................................................ .......................................... 163 16.0 comparator module.......................................................................................................... ........................................................ 173 17.0 comparator voltage reference module ........................................................................................ ........................................... 177 18.0 low-voltage detect (lvd)................................................................................................... ..................................................... 179 19.0 special features of the cpu ................................................................................................ .................................................... 183 20.0 development support........................................................................................................ ....................................................... 203 21.0 instruction set summary .................................................................................................... ...................................................... 207 22.0 electrical characteristics ................................................................................................. ......................................................... 257 23.0 dc and ac characteristics graphs and tables ................................................................................ ....................................... 287 24.0 packaging information...................................................................................................... ........................................................ 289 appendix a: revision history................................................................................................... .......................................................... 295 appendix b: device differences................................................................................................. ........................................................ 295 appendix c: conversion considerations .......................................................................................... ................................................. 296 appendix d: migration from baseline to enhanced devices........................................................................ ...................................... 296 appendix e: migration from mid-range to enhanced devices ....................................................................... ................................. 297 appendix f: migration from high-end to enhanced devices ........................................................................ ..................................... 297 index .......................................................................................................................... ....................................................................... 299 the microchip web site ......................................................................................................... ............................................................ 307 customer change notification service ........................................................................................... ................................................... 307 customer support ............................................................................................................... ............................................................... 307 reader response ................................................................................................................ .............................................................. 308 pic18f1230/1330 product identification system .................................................................................. ............................................ 309
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 5 to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/doc umentation issues become known to us, we will publis h an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particul ar device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please spec ify which device, revision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
pic18f1230/1330 ds39758b-page 6 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 7 1.0 device overview this document contains device-specific information for the following devices: this family offers the advantages of all pic18 micro- controllers ? namely, high computational performance at an economical price ? with the addition of high- endurance enhanced flash program memory. on top of these features, the pic18f1230/1330 family introduces design enhancements that make these microcontrollers a logical choice for many high-performance, power control and motor control applications. peripheral highlights include: ? 14-bit resolution power control pwm module (pcpwm) with programmable dead-time insertion the pcpwm can generate up to six complementary pwm outputs with dead-band time insertion. overdrive current is detected by off-chip analog comparators or the digital fault input (flta ). pic18f1230/1330 devices also feature flash program memory and an internal rc oscillator. 1.1 new core features 1.1.1 nanowatt technology all of the devices in the pic18f1230/1330 family incor- porate a range of features that can significantly reduce power consumption during operation. key items include: ? alternate run modes: by clocking the controller from the timer1 source or the internal oscillator block, power consumption during code execution can be reduced by as much as 90%. ? multiple idle modes: the controller can also run with its cpu core disabled but the peripherals still active. in these states, power consumption can be reduced even further, to as little as 4% of normal operation requirements. ? on-the-fly mode switching: the power-managed modes are invoked by user code during operation, allowing the user to incorporate power-saving ideas into their application?s software design. ? low consumption in key modules: the power requirements for both timer1 and the watchdog timer are minimized. see section 22.0 ?electrical characteristics? for values. 1.1.2 multiple oscillator options and features all of the devices in the pic18f1230/1330 family offer ten different oscillator options, allowing users a wide range of choices in developing application hardware. these include: ? four crystal modes, using crystals or ceramic resonators. ? two external clock modes, offering the option of using two pins (oscillator input and a divide-by-4 clock output) or one pin (oscillator input, with the second pin reassigned as general i/o). ? two external rc oscillator modes with the same pin options as the external clock modes. ? an internal oscillator block which provides an 8 mhz clock and an intrc source (approximately 31 khz), as well as a range of six user-selectable clock frequencies, between 125 khz to 4 mhz, for a total of eight clock frequencies. this option frees the two oscillator pins for use as additional general purpose i/os. ? a phase lock loop (pll) frequency multiplier, available to both the high-speed crystal and internal oscillator modes, which allows clock speeds of up to 40 mhz. used with the internal oscillator, the pll gives users a complete selection of clock speeds, from 31 khz to 32 mhz, all without using an external crystal or clock circuit. besides its availability as a clock source, the internal oscillator block provides a stable reference source that gives the family additional features for robust operation: ? fail-safe clock monitor: this option constantly monitors the main clock source against a reference signal provided by the internal oscillator. if a clock failure occurs, the controller is switched to the internal oscillator block, allowing for continued low-speed operation or a safe application shutdown. ? two-speed start-up: this option allows the internal oscillator to serve as the clock source from power-on reset, or wake-up from sleep mode, until the primary clock source is available. ? pic18f1230 ? pic18f1330
pic18f1230/1330 ds39758b-page 8 advance information ? 2006 microchip technology inc. 1.2 other special features ? memory endurance: the enhanced flash cells for both program memory and data eeprom are rated to last for many thousands of erase/write cycles ? up to 100,000 for program memory and 1,000,000 for eeprom. data retention without refresh is conservatively estimated to be greater than 40 years. ? self-programmability: these devices can write to their own program memory spaces under internal software control. by using a bootloader routine located in the protected boot block at the top of program memory, it becomes possible to create an application that can update itself in the field. ? extended instruction set: the pic18f1230/1330 family introduces an optional extension to the pic18 instruction set, which adds eight new instructions and an indexed addressing mode. this extension, enabled as a device configuration option, has been specifically designed to optimize re-entrant application code originally developed in high-level languages, such as c. ? power control pwm module: this module provides up to six modulated outputs for controlling half-bridge and full-bridge drivers. other features include auto-shutdown on fault detection and auto-restart to reactivate outputs once the condition has cleared. ? enhanced addressable usart: this serial communication module is capable of standard rs-232 operation and provides support for the lin bus protocol. other enhancements include automatic baud rate detection and a 16-bit baud rate generator for improved resolution. when the microcontroller is using the internal oscillator block, the eusart provides stable operation for applica- tions that talk to the outside world without using an external crystal (or its accompanying power requirement). ? 10-bit a/d converter: this module incorporates programmable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period and thus, reducing code overhead. ? extended watchdog timer (wdt): this enhanced version incorporates a 16-bit prescaler, allowing an extended time-out range that is stable across operating voltage and temperature. see section 22.0 ?electrical characteristics? for time-out periods. 1.3 details on individual family members devices in the pic18f1230/1330 family are available in 18-pin, 20-pin and 28-pin packages. the devices are differentiated from each other in one way: 1. flash program memory (4 kbytes for pic18f1230, 8 kbytes for pic18f1330). all other features for devices in this family are identical. these are summarized in table 1-1. a block diagram of the pic18f1220/1320 device archi- tecture is provided in figure 1-1. the pinouts for this device family are listed in table 1-2. like all microchip pic18 devices, members of the pic18f1230/1330 family are available as both stan- dard and low-voltage devices. standard devices with enhanced flash memory, designated with an ?f? in the part number (such as pic18 f 1330), accommodate an operating v dd range of 4.2v to 5.5v. low-voltage parts, designated by ?lf? (such as pic18 lf 1330), function over an extended v dd range of 2.0v to 5.5v.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 9 table 1-1: device features features pic18f1230 pic18f1330 operating frequency dc ? 40 mhz dc ? 40 mhz program memory (bytes) 4096 8192 program memory (instructions) 2048 4096 data memory (bytes) 256 256 data eeprom memory (bytes) 128 128 interrupt sources 17 17 i/o ports ports a, b ports a, b timers 2 2 power control pwm module 6 channels 6 channels serial communications enhanced usart enhanced usart 10-bit analog-to-digital module 4 input channels 4 input channels resets (and delays) por, bor, reset instruction, stack full, stack underflow (pwrt, ost), mclr (optional), wdt por, bor, reset instruction, stack full, stack underflow (pwrt, ost), mclr (optional), wdt programmable low-voltage detect yes yes programmable brown-out reset yes yes instruction set 75 instructions; 83 with extended instruction set enabled 75 instructions; 83 with extended instruction set enabled packages 18-pin pdip 18-pin soic 20-pin ssop 28-pin qfn 18-pin pdip 18-pin soic 20-pin ssop 28-pin qfn
pic18f1230/1330 ds39758b-page 10 advance information ? 2006 microchip technology inc. figure 1-1: pic18f1230/1330 (18-pin) block diagram instruction decode & control porta ra2/tx/ck enhanced timer0 timer1 pcpwm mclr /v pp /ra5 (1) /flta (4) ra4/t0cki/an2/v ref + ra1/an1/int1/kbi1 ra0/an0/int0/kbi0/cmp0 data latch data ram address latch address<12> 12 bsr fsr0 fsr1 fsr2 4 12 4 pch pcl pclath 8 31 level stack program counter prodl prodh 8 x 8 multiply wreg 8 bit op 8 8 alu<8> 8 address latch (8 kbytes) data latch 20 21 21 16 8 8 8 inc/dec logic 21 8 data bus<8> 8 instruction 12 3 rom latch bank0, f pclatu pcu ra3/rx/dt usart 8 register table latch ta b l e p o i n t e r < 2 > inc/dec logic rb0/pwm0 decode power-up timer power-on reset watchdog timer v dd , v ss brown-out reset precision reference voltage low-voltage programming in-circuit debugger oscillator start-up timer timing generation osc1 (2) osc2 (2) t1osi t1oso intrc oscillator fail-safe clock monitor note 1: ra5 is available only when the mclr reset is disabled. 2: osc1, osc2, clki and clko are only available in sele ct oscillator modes and when these pins are not being used as digital i/o. refer to section 2.0 ?oscillator configurations? for additional information. 3: placement of t1osi and t1oso/t1cki depends on the value of the configuration bit, t1oscmx, of config3h. 4: placement of flta depends on the value of the configuration bit, fltamx, of config3h. 8 program memory (4 kbytes) pic18f1230 pic18f1330 10-bit data eeprom mclr (1) bor lvd a/d converter rb1/pwm1 rb7/pwm5/pgd ra6/osc2 (2) /clko (2) / ra7/osc1 (2) /clki (2) / rb2/int2/kbi2/cmp2/ rb3/int3/kbi3/cmp1/ rb6/pwm4/pgc rb5/pwm3 rb4/pwm2 portb t1osi (3) t1oso (3) /t1cki (3) t1osi (3) /flta (4) t1oso (3) /t1cki (3) /an3
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 11 table 1-2: pic18f1230/1330 pinout i/o descriptions pin name pin number pin type buffer type description pdip, soic ssop qfn mclr /v pp /ra5/flta mclr v pp ra5 flta (1) 441 i i i i st analog st st master clear (input), programming voltage (input) or fault detect input. master clear (reset) input. this pin is an active-low reset to the device. programming voltage input. digital input. fault detect input for pwm. ra7/osc1/clki/ t1osi/flta ra7 osc1 clki t1osi (2) flta (1) 16 18 21 i/o i i i i st analog analog analog st oscillator crystal, external clock input, timer1 oscillator input or fault detect input. digital i/o. oscillator crystal input or external clock source input. external clock source input. timer1 oscillator input. fault detect input for pwm. ra6/osc2/clko/ t1oso/t1cki/an3 ra6 osc2 clko t1oso (2) ticki (2) an3 15 17 20 i/o o o o i i st analog analog analog st analog oscillator crystal, clock output, timer1 oscillator output or analog input. digital i/o. oscillator crystal output or external clock source input. external clock source output. timer1 oscillator output. timer1 clock input. analog input 3. legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power note 1: placement of flta depends on the value of configuration bit, fltamx, of config3h. 2: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h.
pic18f1230/1330 ds39758b-page 12 advance information ? 2006 microchip technology inc. porta is a bidirectional i/o port. ra0/an0/int0/kbi0/ cmp0 ra0 an0 int0 kbi0 cmp0 1126 i/o i i i i ttl analog st ttl analog digital i/o. analog input 0. external interrupt 0. interrupt-on-change pin. comparator 0 input. ra1/an1/int1/kbi1 ra1 an1 int1 kbi1 2227 i/o i i i ttl analog st ttl digital i/o. analog input 1. external interrupt 1. interrupt-on-change pin. ra2/tx/ck ra2 tx ck 677 i/o o i/o ttl ? st digital i/o. eusart asynchronous transmit. eusart synchronous clock. ra3/rx/dt ra3 rx dt 788 i/o i i/o ttl st st digital i/o. eusart asynchronous receive. eusart synchronous data. ra4/t0cki/an2/v ref + ra4 t0cki an2 v ref + 3328 i/o i i i ttl st analog analog digital i/o. timer0 external clock input. analog input 2. a/d reference voltage (high) input. table 1-2: pic18f1230/1330 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip, soic ssop qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power note 1: placement of flta depends on the value of configuration bit, fltamx, of config3h. 2: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 13 portb is a bidirectional i/o port. rb0/pwm0 rb0 pwm0 899 i/o o ttl ? digital i/o. pwm module output pwm0. rb1/pwm1 rb1 pwm1 91010 i/o o ttl ? digital i/o. pwm module output pwm1. rb2/int2/kbi2/cmp2/ t1oso/t1cki rb2 int2 kbi2 cmp2 t1oso (2) t1cki (2) 17 19 23 i/o i i i o i ttl st ttl analog analog st digital i/o. external interrupt 2. interrupt-on-change pin. comparator 2 input. timer1 oscillator output. timer1 clock input. rb3/int3/kbi3/cmp1/ t1osi rb3 int3 kbi3 cmp1 t1osi (2) 18 20 24 i/o i i i i ttl st ttl analog analog digital i/o. external interrupt 3. interrupt-on-change pin. comparator 1 input. timer1 oscillator input. rb4/pwm2 rb4 pwm2 10 11 12 i/o o ttl ? digital i/o. pwm module output pwm2. rb5/pwm3 rb5 pwm3 11 12 13 i/o o ttl ? digital i/o. pwm module output pwm3. rb6/pwm4/pgc rb6 pwm4 pgc 12 13 15 i/o o i ttl ? st digital i/o. pwm module output pwm4. in-circuit debugger and icsp? programming clock pin. rb7/pwm5/pgd rb7 pwm5 pgd 13 14 16 i/o o o ttl ? ? digital i/o. pwm module output pwm5. in-circuit debugger and icsp programming data pin. table 1-2: pic18f1230/1330 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip, soic ssop qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power note 1: placement of flta depends on the value of configuration bit, fltamx, of config3h. 2: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h.
pic18f1230/1330 ds39758b-page 14 advance information ? 2006 microchip technology inc. v ss 5 5 3 p ? ground reference for logic and i/o pins. v dd 14 16 19 p ? positive supply for logic and i/o pins. av ss 5 6 5 p ? ground reference for a/d converter module. av dd 14 15 17 p ? positive supply for a/d converter module. nc ? ? 2, 4, 6, 11, 14, 18, 22, 25 ? ? no connect. table 1-2: pic18f1230/1330 pinout i/o descriptions (continued) pin name pin number pin type buffer type description pdip, soic ssop qfn legend: ttl = ttl compatible input cmos = cmos compatible input or output st = schmitt trigger input with cmos levels i = input o = output p = power note 1: placement of flta depends on the value of configuration bit, fltamx, of config3h. 2: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 15 2.0 oscillator configurations 2.1 oscillator types pic18f1230/1330 devices can be operated in ten different oscillator modes. the user can program the configuration bits, fosc3:fosc0, in configuration register 1h to select one of these ten modes: 1. lp low-power crystal 2. xt crystal/resonator 3. hs high-speed crystal/resonator 4. hspll high-speed crystal/resonator with pll enabled 5. rc external resistor/capacitor with f osc /4 output on ra6 6. rcio external resistor/capacitor with i/o on ra6 7. intio1 internal oscillator with f osc /4 output on ra6 and i/o on ra7 8. intio2 internal oscillator with i/o on ra6 and ra7 9. ec external clock with f osc /4 output 10. ecio external clock with i/o on ra6 2.2 crystal oscillator/ceramic resonators in xt, lp, hs or hspll oscillator modes, a crystal or ceramic resonator is connected to the osc1 and osc2 pins to establish oscillation. figure 2-1 shows the pin connections. the oscillator design requires the use of a parallel cut crystal. figure 2-1: crystal/ceramic resonator operation (xt, lp, hs or hspll configuration) table 2-1: capacitor selection for ceramic resonators note: use of a series cut crystal may give a fre- quency out of the crystal manufacturer?s specifications. typical capacitor values used: mode freq osc1 osc2 xt 3.58 mhz 4.19 mhz 4 mhz 4 mhz 15 pf 15 pf 30 pf 50 pf 15 pf 15 pf 30 pf 50 pf capacitor values are for design guidance only. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes following table 2-2 for additional information. note 1: see table 2-1 and table 2-2 for initial values of c1 and c2. 2: a series resistor (r s ) may be required for at strip cut crystals. 3: r f varies with the oscillator mode chosen. c1 (1) c2 (1) xtal osc2 osc1 r f (3) sleep to logic pic18fxxxx r s (2) internal
pic18f1230/1330 ds39758b-page 16 advance information ? 2006 microchip technology inc. table 2-2: capacitor selection for crystal oscillator an external clock source may also be connected to the osc1 pin in the hs mode, as shown in figure 2-2. figure 2-2: external clock input operation (hs oscillator configuration) 2.3 external clock input the ec and ecio oscillator modes require an external clock source to be connected to the osc1 pin. there is no oscillator start-up time required after a power-on reset or after an exit from sleep mode. in the ec oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 2-3 shows the pin connections for the ec oscillator mode. figure 2-3: external clock input operation (ec configuration) the ecio oscillator mode functions like the ec mode, except that the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 2-4 shows the pin connections for the ecio oscillator mode. figure 2-4: external clock input operation (ecio configuration) osc type crystal freq typical capacitor values tested: c1 c2 lp 32 khz 30 pf 30 pf xt 1 mhz 4 mhz 15 pf 15 pf 15 pf 15 pf hs 4 mhz 10 mhz 20 mhz 25 mhz 15 pf 15 pf 15 pf 15 pf 15 pf 15 pf 15 pf 15 pf capacitor values are for design guidance only. different capacitor values may be required to produce acceptable oscillator operation. the user should test the performance of the oscillator over the expected v dd and temperature range for the application. see the notes following this table for additional information. note 1: higher capacitance increases the stability of the oscillator but also increases the start-up time. 2: when operating below 3v v dd , or when using certain ceramic resonators at any voltage, it may be necessary to use the hs mode or switch to a crystal oscillator. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 4: rs may be required to avoid overdriving crystals with low drive level specification. 5: always verify oscillator performance over the v dd and temperature range that is expected for the application. osc1 osc2 open clock from ext. system pic18fxxxx (hs mode) osc1/clki osc2/clko f osc /4 clock from ext. system pic18fxxxx osc1/clki i/o (osc2) ra6 clock from ext. system pic18fxxxx
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 17 2.4 rc oscillator for timing insensitive applications, the ?rc? and ?rcio? device options offer additional cost savings. the actual oscillator frequency is a function of several factors: ? supply voltage ? values of the external resistor (r ext ) and capacitor (c ext ) ? operating temperature given the same device, operating voltage and temperature and component values, there will also be unit-to-unit frequency variations. these are due to factors such as: ? normal manufacturing variation ? difference in lead frame capacitance between package types (especially for low c ext values) ? variations within the tolerance of limits of r ext and c ext in the rc oscillator mode, the oscillator frequency divided by 4 is available on the osc2 pin. this signal may be used for test purposes or to synchronize other logic. figure 2-5 shows how the r/c combination is connected. figure 2-5: rc oscillator mode the rcio oscillator mode (figure 2-6) functions like the rc mode, except that the osc2 pin becomes an additional general purpose i/o pin. the i/o pin becomes bit 6 of porta (ra6). figure 2-6: rcio oscillator mode 2.5 pll frequency multiplier a phase locked loop (pll) circuit is provided as an option for users who wish to use a lower frequency oscillator circuit or to clock the device up to its highest rated frequency from a crystal oscillator. this may be useful for customers who are concerned with emi due to high-frequency crystals or users who require higher clock speeds from an internal oscillator. 2.5.1 hspll oscillator mode the hspll mode makes use of the hs mode oscillator for frequencies up to 10 mhz. a pll then multiplies the oscillator output frequency by 4 to produce an internal clock frequency up to 40 mhz. the pllen bit is not available in this oscillator mode. the pll is only available to the crystal oscillator when the fosc3:fosc0 configuration bits are programmed for hspll mode (= 0110 ). figure 2-7: pll block diagram (hs mode) 2.5.2 pll and intosc the pll is also available to the internal oscillator block in selected oscillator modes. in this configuration, the pll is enabled in software and generates a clock output of up to 32 mhz. the operation of intosc with the pll is described in section 2.6.4 ?pll in intosc modes? . osc2/clko c ext r ext pic18fxxxx osc1 f osc /4 internal clock v dd v ss recommended values: 3 k r ext 100 k c ext > 20 pf c ext r ext pic18fxxxx osc1 internal clock v dd v ss recommended values: 3 k r ext 100 k c ext > 20 pf i/o (osc2) ra6 mux vco loop filter crystal osc osc2 osc1 pll enable f in f out sysclk phase comparator hs oscillator enable 4 (from configuration register 1h) hs mode
pic18f1230/1330 ds39758b-page 18 advance information ? 2006 microchip technology inc. 2.6 internal oscillator block the pic18f1230/1330 devices include an internal oscillator block which generates two different clock signals; either can be used as the microcontroller?s clock source. this may eliminate the need for external oscillator circuits on the osc1 and/or osc2 pins. the main output (intosc) is an 8 mhz clock source, which can be used to directly drive the device clock. it also drives a postscaler, which can provide a range of clock frequencies from 31 khz to 4 mhz. the intosc output is enabled when a clock frequency from 125 khz to 8 mhz is selected. the other clock source is the internal rc oscillator (intrc), which provides a nominal 31 khz output. intrc is enabled if it is selected as the device clock source; it is also enabled automatically when any of the following are enabled: ? power-up timer ? fail-safe clock monitor ? watchdog timer ? two-speed start-up these features are discussed in greater detail in section 19.0 ?special features of the cpu? . the clock source frequency (intosc direct, intrc direct or intosc postscaler) is selected by configuring the ircf bits of the osccon register (page 22). 2.6.1 intio modes using the internal oscillator as the clock source eliminates the need for up to two external oscillator pins, which can then be used for digital i/o. two distinct configurations are available: ? in intio1 mode, the osc2 pin outputs f osc /4, while osc1 functions as ra7 for digital input and output. ? in intio2 mode, osc1 functions as ra7 and osc2 functions as ra6, both for digital input and output. 2.6.2 intosc output frequency the internal oscillator block is calibrated at the factory to produce an intosc output frequency of 8.0 mhz. the intrc oscillator operates independently of the intosc source. any changes in intosc across voltage and temperature are not necessarily reflected by changes in intrc and vice versa. 2.6.3 osctune register the internal oscillator?s output has been calibrated at the factory but can be adjusted in the user?s application. this is done by writing to the osctune register (register 2-1). the tuning sensitivity is constant throughout the tuning range. when the osctune register is modified, the intosc frequency will begin shifting to the new frequency. the intrc clock will reach the new frequency within 8 clock cycles (approximately 8 * 32 s=256 s). the intosc clock will stabilize within 1 ms. code execution continues during this shift. there is no indication that the shift has occurred. the osctune register also implements the intsrc and pllen bits, which control certain features of the internal oscillator block. the intsrc bit allows users to select which internal oscillator provides the clock source when the 31 khz frequency option is selected. this is covered in greater detail in section 2.7.1 ?oscillator control register? . the pllen bit controls the operation of the frequency multiplier, pll, in internal oscillator modes. 2.6.4 pll in intosc modes the 4x frequency multiplier can be used with the internal oscillator block to produce faster device clock speeds than are normally possible with an internal oscillator. when enabled, the pll produces a clock speed of up to 32 mhz. unlike hspll mode, the pll is controlled through software. the control bit, pllen (osctune<6>), is used to enable or disable its operation. the pll is available when the device is configured to use the internal oscillator block as its primary clock source (fosc3:fosc0 = 1001 or 1000 ). additionally, the pll will only function when the selected output fre- quency is either 4 mhz or 8 mhz (osccon<6:4> = 111 or 110 ). if both of these conditions are not met, the pll is disabled. the pllen control bit is only functional in those internal oscillator modes where the pll is available. in all other modes, it is forced to ? 0 ? and is effectively unavailable. 2.6.5 intosc frequency drift the factory calibrates the internal oscillator block output (intosc) for 8 mhz. however, this frequency may drift as v dd or temperature changes, which can affect the controller operation in a variety of ways. it is possible to adjust the intosc frequency by modifying the value in the osctune register. this has no effect on the intrc clock source frequency. tuning the intosc source requires knowing when to make the adjustment, in which direction it should be made and in some cases, how large a change is needed. two compensation techniques are discussed in section 2.6.5.1 ?compensating with the eusart? and section 2.6.5.2 ?compensating with the timers? , but other techniques may be used.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 19 2.6.5.1 compensating with the eusart an adjustment may be required when the eusart begins to generate framing errors or receives data with errors while in asynchronous mode. framing errors indicate that the device clock frequency is too high; to adjust for this, decrement the value in osctune to reduce the clock frequency. on the other hand, errors in data may suggest that the clock speed is too low; to compensate, increment osctune to increase the clock frequency. 2.6.5.2 compensating with the timers this technique compares device clock speed to some reference clock. two timers may be used; one timer is clocked by the peripheral clock, while the other is clocked by a fixed reference source, such as the timer1 oscillator. both timers are cleared, but the timer clocked by the reference generates interrupts. when an interrupt occurs, the internally clocked timer is read and both timers are cleared. if the internally clocked timer value is greater than expected, then the internal oscillator block is running too fast. to adjust for this, decrement the osctune register. register 2-1: osctune: oscillator tuning register r/w-0 r/w-0 (1) u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 intsrc pllen (1) ? tun4 tun3 tun2 tun1 tun0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 intsrc: internal oscillator low-frequency source select bit 1 = 31.25 khz device clock derived from 8 mhz intosc source (divide-by-256 enabled) 0 = 31 khz device clock derived directly from intrc internal oscillator bit 6 pllen: frequency multiplier pll for intosc enable bit (1) 1 = pll enabled for intosc (4 mhz and 8 mhz only) 0 = pll disabled bit 5 unimplemented: read as ? 0 ? bit 4-0 tun4:tun0: frequency tuning bits 01111 = maximum frequency ? ? ? ? 00001 00000 = center frequency. oscillator module is running at the calibrated frequency. 11111 ? ? ? ? 10000 = minimum frequency note 1: available only in certain oscillator configurations; otherwise, this bit is unavailable and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? for details.
pic18f1230/1330 ds39758b-page 20 advance information ? 2006 microchip technology inc. 2.7 clock sources and oscillator switching like previous pic18 devices, the pic18f1230/1330 family includes a feature that allows the device clock source to be switched from the main oscillator to an alternate low-frequency clock source. pic18f1230/1330 devices offer two alternate clock sources. when an alter- nate clock source is enabled, the various power-managed operating modes are available. essentially, there are three clock sources for these devices: ? primary oscillators ? secondary oscillators ? internal oscillator block the primary oscillators include the external crystal and resonator modes, the external rc modes, the external clock modes and the internal oscillator block. the particular mode is defined by the fosc3:fosc0 configuration bits. the details of these modes are covered earlier in this chapter. the secondary oscillators are those external sources not connected to the osc1 or osc2 pins. these sources may continue to operate even after the controller is placed in a power-managed mode. pic18f1230/1330 devices offer the timer1 oscillator as a secondary oscillator. this oscillator, in all power- managed modes, is often the time base for functions such as a real-time clock. most often, a 32.768 khz watch crystal is connected between the t1oso/t1cki and t1osi pins. like the lp mode oscillator circuit, loading capacitors are also connected from each pin to ground. the timer1 oscil- lator is discussed in greater detail in section 12.2 ?timer1 oscillator? . in addition to being a primary clock source, the internal oscillator block is available as a power-managed mode clock source. the intrc source is also used as the clock source for several special features, such as the wdt and fail-safe clock monitor. the clock sources for the pic18f1230/1330 devices are shown in figure 2-8. see section 19.0 ?special features of the cpu? for configuration register details. figure 2-8: pic18f1230/1330 clock diagram pic18f1230/1330 4 x pll fosc3:fosc0 t1oscen enable oscillator t1oso t1osi clock source option for other modules osc1 osc2 sleep hspll, intosc/pll lp, xt, hs, rc, ec t1osc cpu peripherals idlen postscaler mux mux 8 mhz 4 mhz 2 mhz 1 mhz 500 khz 125 khz 250 khz osccon<6:4> 111 110 101 100 011 010 001 000 31 khz intrc source internal oscillator block wdt, pwrt, fscm 8 mhz internal oscillator (intosc) osccon<6:4> clock control osccon<1:0> source 8 mhz 31 khz (intrc) osctune<6> 0 1 osctune<7> and two-speed start-up primary oscillator secondary oscillator
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 21 2.7.1 oscillator control register the osccon register (register 2-2) controls several aspects of the device clock?s operation, both in full power operation and in power-managed modes. the system clock select bits, scs1:scs0, select the clock source. the available clock sources are the primary clock (defined by the fosc3:fosc0 configuration bits), the secondary clock (timer1 oscillator) and the internal oscillator block. the clock source changes immediately after one or more of the bits is written to, following a brief clock transition interval. the scs bits are cleared on all forms of reset. the internal oscillator frequency select bits (ircf2:ircf0) select the frequency output of the internal oscillator block to drive the device clock. the choices are the intrc source, the intosc source (8 mhz) or one of the frequencies derived from the intosc postscaler (31.25 khz to 4 mhz). if the internal oscillator block is supplying the device clock, changing the states of these bits will have an immedi- ate change on the internal oscillator?s output. on device resets, the default output frequency of the internal oscillator block is set at 1 mhz. when a nominal output frequency of 31 khz is selected (ircf2:ircf0 = 000 ), users may choose which internal oscillator acts as the source. this is done with the intsrc bit in the osctune register (osctune<7>). setting this bit selects intosc as a 31.25 khz clock source by enabling the divide-by-256 output of the intosc postscaler. clearing intsrc selects intrc (nominally 31 khz) as the clock source. this option allows users to select the tunable and more precise intosc as a clock source, while maintaining power savings with a very low clock speed. regardless of the setting of intsrc, intrc always remains the clock source for features such as the watchdog timer and the fail-safe clock monitor. the osts, iofs and t1run bits indicate which clock source is currently providing the device clock. the osts bit indicates that the oscillator start-up timer has timed out and the primary clock is providing the device clock in primary clock modes. the iofs bit indicates when the internal oscillator block has stabilized and is providing the device clock in rc clock modes. the t1run bit (t1con<6>) indicates when the timer1 oscillator is providing the device clock in secondary clock modes. in power-managed modes, only one of these three bits will be set at any time. if none of these bits are set, the intrc is providing the clock or the internal oscillator block has just started and is not yet stable. the idlen bit determines if the device goes into sleep mode or one of the idle modes when the sleep instruction is executed. the use of the flag and control bits in the osccon register is discussed in more detail in section 3.0 ?power-managed modes? . 2.7.2 oscillator transitions pic18f1230/1330 devices contain circuitry to prevent clock ?glitches? when switching between clock sources. a short pause in the device clock occurs during the clock switch. the length of this pause is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. clock transitions are discussed in greater detail in section 3.1.2 ?entering power-managed modes? . note 1: the timer1 oscillator must be enabled to select the secondary clock source. the timer1 oscillator is enabled by setting the t1oscen bit in the timer1 control regis- ter (t1con<3>). if the timer1 oscillator is not enabled, then any attempt to select a secondary clock source will be ignored. 2: it is recommended that the timer1 oscillator be operating and stable before selecting the secondary clock source or a very long delay may occur while the timer1 oscillator starts.
pic18f1230/1330 ds39758b-page 22 advance information ? 2006 microchip technology inc. register 2-2: osccon: oscillator control register r/w-0 r/w-1 r/w-0 r/w-0 r (1) r-0 r/w-0 r/w-0 idlen ircf2 ircf1 ircf0 osts iofs scs1 scs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 idlen: idle enable bit 1 = device enters idle mode on sleep instruction 0 = device enters sleep mode on sleep instruction bit 6-4 ircf2:ircf0: internal oscillator frequency select bits 111 = 8 mhz (intosc drives clock directly) 110 = 4 mhz 101 = 2 mhz 100 = 1 mhz (3) 011 = 500 khz 010 = 250 khz 001 = 125 khz 000 = 31 khz (from either intosc/256 or intrc directly) (2) bit 3 osts: oscillator start-up time-out status bit (1) 1 = oscillator start-up timer time-out has expired; primary oscillator is running 0 = oscillator start-up timer time-out is running; primary oscillator is not ready bit 2 iofs: intosc frequency stable bit 1 = intosc frequency is stable 0 = intosc frequency is not stable bit 1-0 scs1:scs0: system clock select bits 1x = internal oscillator block 01 = secondary (timer1) oscillator 00 = primary oscillator note 1: reset state depends on state of the ieso configuration bit. 2: source selected by the intsrc bit (osctune<7>), see text. 3: default output frequency of intosc on reset.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 23 2.8 effects of power-managed modes on the various clock sources when pri_idle mode is selected, the designated primary oscillator continues to run without interruption. for all other power-managed modes, the oscillator using the osc1 pin is disabled. the osc1 pin (and osc2 pin, if used by the oscillator) will stop oscillating. in secondary clock modes (sec_run and sec_idle), the timer1 oscillator is operating and providing the device clock. the timer1 oscillator may also run in all power-managed modes if required to clock timer1 or timer3. in internal oscillator modes (rc_run and rc_idle), the internal oscillator block provides the device clock source. the 31 khz intrc output can be used directly to provide the clock and may be enabled to support various special features, regardless of the power- managed mode (see section 19.2 ?watchdog timer (wdt)? , section 19.3 ?two-speed start-up? and section 19.4 ?fail-safe clock monitor? for more information on wdt, fail-safe clock monitor and two- speed start-up). the intosc output at 8 mhz may be used directly to clock the device or may be divided down by the postscaler. the intosc output is disabled if the clock is provided directly from the intrc output. if the sleep mode is selected, all clock sources are stopped. since all the transistor switching currents have been stopped, sleep mode achieves the lowest current consumption of the device (only leakage currents). enabling any on-chip feature that will operate during sleep will increase the current consumed during sleep. the intrc is required to support wdt operation. the timer1 oscillator may be operating to support a real- time clock. other features may be operating that do not require a device clock source (i.e., intn pins and others). peripherals that may add significant current consumption are listed in section 22.0 ?electrical characteristics? . 2.9 power-up delays power-up delays are controlled by two timers, so that no external reset circuitry is required for most applications. the delays ensure that the device is kept in reset until the device power supply is stable under normal circumstances and the primary clock is operating and stable. for additional information on power-up delays, see section 4.5 ?device reset timers? . the first timer is the power-up timer (pwrt), which provides a fixed delay on power-up (parameter 33, table 22-10). it is enabled by clearing (= 0 ) the pwrten configuration bit. the second timer is the oscillator start-up timer (ost), intended to keep the chip in reset until the crystal oscillator is stable (lp, xt and hs modes). the ost does this by counting 1024 oscillator cycles before allowing the oscillator to clock the device. when the hspll oscillator mode is selected, the device is kept in reset for an additional 2 ms, following the hs mode ost delay, so the pll can lock to the incoming clock frequency. there is a delay of interval t csd (parameter 38, table 22-10), following por, while the controller becomes ready to execute instructions. this delay runs concurrently with any other delays. this may be the only delay that occurs when any of the ec, rc or intio modes are used as the primary clock source. table 2-3: osc1 and osc2 pin states in sleep mode oscillator mode osc1 pin osc2 pin rc, intio1 floating, external resistor should pull high at logic low (clock/4 output) rcio floating, external resistor should pull high configured as porta, bit 6 intio2 configured as porta, bit 7 configured as porta, bit 6 ecio floating, pulled by external clock configured as porta, bit 6 ec floating, pulled by external clock at logic low (clock/4 output) lp, xt and hs feedback inverter disabled at quiescent voltage level feedback inverter disabled at quiescent voltage level note: see table 4-2 in section 4.0 ?reset? for time-outs due to sleep and mclr reset.
pic18f1230/1330 ds39758b-page 24 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 25 3.0 power-managed modes pic18f1230/1330 devices offer a total of seven operating modes for more efficient power management. these modes provide a variety of options for selective power conservation in applications where resources may be limited (i.e., battery-powered devices). there are three categories of power-managed modes: ? run modes ? idle modes ? sleep mode these categories define which portions of the device are clocked and sometimes, what speed. the run and idle modes may use any of the three available clock sources (primary, secondary or internal oscillator block); the sleep mode does not use a clock source. the power-managed modes include several power- saving features offered on previous picmicro ? devices. one is the clock switching feature, offered in other pic18 devices, allowing the controller to use the timer1 oscillator in place of the primary oscillator. also included is the sleep mode, offered by all picmicro devices, where all device clocks are stopped. 3.1 selecting power-managed modes selecting a power-managed mode requires two decisions: if the cpu is to be clocked or not and the selection of a clock source. the idlen bit (osccon<7>) controls cpu clocking, while the scs1:scs0 bits (osccon<1:0>) select the clock source. the individual modes, bit settings, clock sources and affected modules are summarized in table 3-1. 3.1.1 clock sources the scs1:scs0 bits allow the selection of one of three clock sources for power-managed modes. they are: ? the primary clock, as defined by the fosc3:fosc0 configuration bits ? the secondary clock (the timer1 oscillator) ? the internal oscillator block (for rc modes) 3.1.2 entering power-managed modes switching from one power-managed mode to another begins by loading the osccon register. the scs1:scs0 bits select the clock source and determine which run or idle mode is to be used. changing these bits causes an immediate switch to the new clock source, assuming that it is running. the switch may also be subject to clock transition delays. these are discussed in section 3.1.3 ?clock transitions and status indicators? and subsequent sections. entry to the power-managed idle or sleep modes is triggered by the execution of a sleep instruction. the actual mode that results depends on the status of the idlen bit. depending on the current mode and the mode being switched to, a change to a power-managed mode does not always require setting all of these bits. many transitions may be done by changing the oscillator select bits, or changing the idlen bit, prior to issuing a sleep instruction. if the idlen bit is already configured correctly, it may only be necessary to perform a sleep instruction to switch to the desired mode. table 3-1: power-managed modes mode osccon bits module clocking available clock and oscillator source idlen<7> (1) scs1:scs0 <1:0> cpu peripherals sleep 0 n/a off off none ? all clocks are disabled pri_run n/a 00 clocked clocked primary ? lp, xt, hs, hspll, rc, ec and internal oscillator block (2) . this is the normal full power execution mode. sec_run n/a 01 clocked clocked secondary ? timer1 oscillator rc_run n/a 1x clocked clocked internal oscillator block (2) pri_idle 100 off clocked primary ? lp, xt, hs, hspll, rc, ec sec_idle 101 off clocked secondary ? timer1 oscillator rc_idle 11x off clocked internal oscillator block (2) note 1: idlen reflects its value when the sleep instruction is executed. 2: includes intosc and intosc postsc aler, as well as the intrc source.
pic18f1230/1330 ds39758b-page 26 advance information ? 2006 microchip technology inc. 3.1.3 clock transitions and status indicators the length of the transition between clock sources is the sum of two cycles of the old clock source and three to four cycles of the new clock source. this formula assumes that the new clock source is stable. three bits indicate the current clock source and its status. they are: ? osts (osccon<3>) ? iofs (osccon<2>) ? t1run (t1con<6>) in general, only one of these bits will be set while in a given power-managed mode. when the osts bit is set, the primary clock is providing the device clock. when the iofs bit is set, the intosc output is providing a stable 8 mhz clock source to a divider that actually drives the device clock. when the t1run bit is set, the timer1 oscillator is providing the clock. if none of these bits are set, then either the intrc clock source is clocking the device, or the intosc source is not yet stable. if the internal oscillator block is configured as the primary clock source by the fosc3:fosc0 configuration bits, then both the osts and iofs bits may be set when in pri_run or pri_idle modes. this indicates that the primary clock (intosc output) is generating a stable 8 mhz output. entering another power-managed rc mode at the same frequency would clear the osts bit. 3.1.4 multiple sleep commands the power-managed mode that is invoked with the sleep instruction is determined by the setting of the idlen bit at the time the instruction is executed. if another sleep instruction is executed, the device will enter the power-managed mode specified by idlen at that time. if idlen has changed, the device will enter the new power-managed mode specified by the new setting. 3.2 run modes in the run modes, clocks to both the core and peripherals are active. the difference between these modes is the clock source. 3.2.1 pri_run mode the pri_run mode is the normal, full power execution mode of the microcontroller. this is also the default mode upon a device reset unless two-speed start-up is enabled (see section 19.3 ?two-speed start-up? for details). in this mode, the osts bit is set. the iofs bit may be set if the internal oscillator block is the primary clock source (see section 2.7.1 ?oscillator control register? ). 3.2.2 sec_run mode the sec_run mode is the compatible mode to the ?clock switching? feature offered in other pic18 devices. in this mode, the cpu and peripherals are clocked from the timer1 oscillator. this gives users the option of lower power consumption while still using a high accuracy clock source. sec_run mode is entered by setting the scs1:scs0 bits to ? 01 ?. the device clock source is switched to the timer1 oscillator (see figure 3-1), the primary oscillator is shut down, the t1run bit (t1con<6>) is set and the osts bit is cleared. on transitions from sec_run to pri_run mode, the peripherals and cpu continue to be clocked from the timer1 oscillator while the primary clock is started. when the primary clock becomes ready, a clock switch back to the primary clock occurs (see figure 3-2). when the clock switch is complete, the t1run bit is cleared, the osts bit is set and the primary clock is providing the clock. the idlen and scs bits are not affected by the wake-up; the timer1 oscillator continues to run. note 1: caution should be used when modifying a single ircf bit. if v dd is less than 3v, it is possible to select a higher clock speed than is supported by the low v dd . improper device operation may result if the v dd /f osc specifications are violated. 2: executing a sleep instruction does not necessarily place the device into sleep mode. it acts as the trigger to place the controller into either the sleep mode or one of the idle modes, depending on the setting of the idlen bit. note: the timer1 oscillator should already be running prior to entering sec_run mode. if the t1oscen bit is not set when the scs1:scs0 bits are set to ? 01 ?, entry to sec_run mode will not occur. if the timer1 oscillator is enabled, but not yet running, device clocks will be delayed until the oscillator has started. in such situa- tions, initial oscillator operation is far from stable and unpredictable operation may result.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 27 figure 3-1: transition timing for entry to sec_run mode figure 3-2: transition timing from sec_run mode to pri_run mode (hspll) 3.2.3 rc_run mode in rc_run mode, the cpu and peripherals are clocked from the internal oscillator block using the intosc multiplexer. in this mode, the primary clock is shut down. when using the intrc source, this mode provides the best power conservation of all the run modes, while still executing code. it works well for user applications which are not highly timing sensitive or do not require high-speed clocks at all times. if the primary clock source is the internal oscillator block (either intrc or intosc), there are no distinguishable differences between pri_run and rc_run modes during execution. however, a clock switch delay will occur during entry to and exit from rc_run mode. therefore, if the primary cl ock source is the internal oscillator block, the use of rc_run mode is not recommended. this mode is entered by setting the scs1 bit to ? 1 ?. although it is ignored, it is recommended that the scs0 bit also be cleared; this is to maintain software compat- ibility with future devices. when the clock source is switched to the intosc multiplexer (see figure 3-3), the primary oscillator is shut down and the osts bit is cleared. the ircf bits may be modified at any time to immediately change the clock speed. q4 q3 q2 osc1 peripheral program q1 t1osi q1 counter clock cpu clock pc + 2 pc 123 n-1n clock transition (1) q4 q3 q2 q1 q3 q2 pc + 4 note 1: clock transition typically occurs within 2-4 t osc . q1 q3 q4 osc1 peripheral program pc t1osi pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. 2: clock transition typically occurs within 2-4 t osc . scs1:scs0 bits changed t pll (1) 12 n-1n clock osts bit set transition (2) t ost (1) note: caution should be used when modifying a single ircf bit. if v dd is less than 3v, it is possible to select a higher clock speed than is supported by the low v dd . improper device operation may result if the v dd /f osc specifications are violated.
pic18f1230/1330 ds39758b-page 28 advance information ? 2006 microchip technology inc. if the ircf bits and the intsrc bit are all clear, the intosc output is not enabled and the iofs bit will remain clear; there will be no indication of the current clock source. the intrc source is providing the device clocks. if the ircf bits are changed from all clear (thus, enabling the intosc output), or if intsrc is set, the iofs bit becomes set after the intosc output becomes stable. clocks to the device continue while the intosc source stabilizes after an interval of t iobst . if the ircf bits were previously at a non-zero value, or if intsrc was set before setting scs1 and the intosc source was already stable, the iofs bit will remain set. on transitions from rc_run mode to pri_run mode, the device continues to be clocked from the intosc multiplexer while the primary clock is started. when the primary clock becomes ready, a clock switch to the primary clock occurs (see figure 3-4). when the clock switch is complete, the iofs bit is cleared, the osts bit is set and the primary clock is providing the device clock. the idlen and scs bits are not affected by the switch. the intrc source will continue to run if either the wdt or the fail-safe clock monitor is enabled. figure 3-3: transition timing to rc_run mode figure 3-4: transition timing fr om rc_run mode to pri_run mode q4 q3 q2 osc1 peripheral program q1 intrc q1 counter clock cpu clock pc + 2 pc 123 n-1n clock transition (1) q4 q3 q2 q1 q3 q2 pc + 4 note 1: clock transition typically occurs within 2-4 t osc . q1 q3 q4 osc1 peripheral program pc intosc pll clock q1 pc + 4 q2 output q3 q4 q1 cpu clock pc + 2 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. 2: clock transition typically occurs within 2-4 t osc . scs1:scs0 bits changed t pll (1) 12 n-1n clock osts bit set transition (2) multiplexer t ost (1)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 29 3.3 sleep mode the power-managed sleep mode in the pic18f1230/ 1330 devices is identical to the legacy sleep mode offered in all other picmicro devices. it is entered by clearing the idlen bit (the default state on device reset) and executing the sleep instruction. this shuts down the selected oscillator (figure 3-5). all clock source status bits are cleared. entering the sleep mode from any other mode does not require a clock switch. this is because no clocks are needed once the controller has entered sleep. if the wdt is selected, the intrc source will continue to operate. if the timer1 oscillator is enabled, it will also continue to run. when a wake event occurs in sleep mode (by interrupt, reset or wdt time-out), the device will not be clocked until the clock source selected by the scs1:scs0 bits becomes ready (see figure 3-6), or it will be clocked from the internal oscillator block if either the two- speed start-up or the fail-safe clock monitor are enabled (see section 19.0 ?special features of the cpu? ). in either case, the osts bit is set when the primary clock is providing the device clocks. the idlen and scs bits are not affected by the wake-up. 3.4 idle modes the idle modes allow the controller?s cpu to be selectively shut down while the peripherals continue to operate. selecting a particular idle mode allows users to further manage power consumption. if the idlen bit is set to a ? 1 ? when a sleep instruction is executed, the peripherals will be clocked from the clock source selected using the scs1:scs0 bits; however, the cpu will not be clocked. the clock source status bits are not affected. setting idlen and executing a sleep instruction provides a quick method of switching from a given run mode to its corresponding idle mode. if the wdt is selected, the intrc source will continue to operate. if the timer1 oscillator is enabled, it will also continue to run. since the cpu is not executing instructions, the only exits from any of the idle modes are by interrupt, wdt time-out or a reset. when a wake event occurs, cpu execution is delayed by an interval of t csd (parameter 38, table 22-10) while it becomes ready to execute code. when the cpu begins executing code, it resumes with the same clock source for the current idle mode. for example, when waking from rc_idle mode, the internal oscillator block will clock the cpu and peripherals (in other words, rc_run mode). the idlen and scs bits are not affected by the wake-up. while in any idle mode or the sleep mode, a wdt time-out will result in a wdt wake-up to the run mode currently specified by the scs1:scs0 bits. figure 3-5: transition timing for entry to sleep mode figure 3-6: transition timing for wake from sleep (hspll) q4 q3 q2 osc1 peripheral sleep program q1 q1 counter clock cpu clock pc + 2 pc q3 q4 q1 q2 osc1 peripheral program pc pll clock q3 q4 output cpu clock q1 q2 q3 q4 q1 q2 clock counter pc + 6 pc + 4 q1 q2 q3 q4 wake event note1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. t ost (1) t pll (1) osts bit set pc + 2
pic18f1230/1330 ds39758b-page 30 advance information ? 2006 microchip technology inc. 3.4.1 pri_idle mode this mode is unique among the three low-power idle modes, in that it does not disable the primary device clock. for timing sensitive applications, this allows for the fastest resumption of device operation with its more accurate primary clock source, since the clock source does not have to ?warm-up? or transition from another oscillator. pri_idle mode is entered from pri_run mode by setting the idlen bit and executing a sleep instruc- tion. if the device is in another run mode, set idlen first, then clear the scs bits and execute sleep . although the cpu is disabled, the peripherals continue to be clocked from the primary clock source specified by the fosc3:fosc0 configuration bits. the osts bit remains set (see figure 3-7). when a wake event occurs, the cpu is clocked from the primary clock source. a delay of interval t csd is required between the wake event and when code execution starts. this is required to allow the cpu to become ready to execute instructions. after the wake- up, the osts bit remains set. the idlen and scs bits are not affected by the wake-up (see figure 3-8). 3.4.2 sec_idle mode in sec_idle mode, the cpu is disabled but the peripherals continue to be clocked from the timer1 oscillator. this mode is entered from sec_run by setting the idlen bit and executing a sleep instruction. if the device is in another run mode, set the idlen bit first, then set the scs1:scs0 bits to ? 01 ? and execute sleep . when the clock source is switched to the timer1 oscillator, the primary oscillator is shut down, the osts bit is cleared and the t1run bit is set. when a wake event occurs, the peripherals continue to be clocked from the timer1 oscillator. after an interval of t csd following the wake event, the cpu begins executing code being clocked by the timer1 oscillator. the idlen and scs bits are not affected by the wake-up; the timer1 oscillator continues to run (see figure 3-8). figure 3-7: transition timing for entry to idle mode figure 3-8: transition timing for wake from idle to run mode note: the timer1 oscillator should already be running prior to entering sec_idle mode. if the t1oscen bit is not set when the sleep instruction is executed, the sleep instruction will be ignored and entry to sec_idle mode will not occur. if the timer1 oscillator is enabled but not yet running, peripheral clocks will be delayed until the oscillator has started. in such situations, initial oscillator operation is far from stable and unpredictable operation may result. q1 peripheral program pc pc + 2 osc1 q3 q4 q1 cpu clock clock counter q2 osc1 peripheral program pc cpu clock q1 q3 q4 clock counter q2 wake event t csd
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 31 3.4.3 rc_idle mode in rc_idle mode, the cpu is disabled but the peripherals continue to be clocked from the internal oscillator block using the intosc multiplexer. this mode allows for controllable power conservation during idle periods. from rc_run, this mode is entered by setting the idlen bit and executing a sleep instruction. if the device is in another run mode, first set idlen, then set the scs1 bit and execute sleep . although its value is ignored, it is recommended that scs0 also be cleared; this is to maintain software compatibility with future devices. the intosc multiplexer may be used to select a higher clock frequency by modifying the ircf bits before executing the sleep instruction. when the clock source is switched to the intosc multiplexer, the primary oscillator is shut down and the osts bit is cleared. if the ircf bits are set to any non-zero value, or the intsrc bit is set, the intosc output is enabled. the iofs bit becomes set, after the intosc output becomes stable, after an interval of t iobst (parameter 39, table 22-10). clocks to the peripherals continue while the intosc source stabilizes. if the ircf bits were previously at a non-zero value, or intsrc was set before the sleep instruction was executed and the intosc source was already stable, the iofs bit will remain set. if the ircf bits and intsrc are all clear, the intosc output will not be enabled, the iofs bit will remain clear and there will be no indication of the current clock source. when a wake event occurs, the peripherals continue to be clocked from the intosc multiplexer. after a delay of t csd following the wake event, the cpu begins executing code being clocked by the intosc multiplexer. the idlen and scs bits are not affected by the wake-up. the intrc source will continue to run if either the wdt or the fail-safe clock monitor is enabled. 3.5 exiting idle and sleep modes an exit from sleep mode or any of the idle modes is triggered by an interrupt, a reset or a wdt time-out. this section discusses the triggers that cause exits from power-managed modes. the clocking subsystem actions are discussed in each of the power-managed modes (see section 3.2 ?run modes?, section 3.3 ?sleep mode? and section 3.4 ?idle modes? ). 3.5.1 exit by interrupt any of the available interrupt sources can cause the device to exit from an idle mode or the sleep mode to a run mode. to enable this functionality, an interrupt source must be enabled by setting its enable bit in one of the intcon or pie registers. the exit sequence is initiated when the corresponding interrupt flag bit is set. on all exits from idle or sleep modes by interrupt, code execution branches to the interrupt vector if the gie/ gieh bit (intcon<7>) is set. otherwise, code execution continues or resumes without branching (see section 10.0 ?interrupts? ). a fixed delay of interval t csd following the wake event is required when leaving sleep and idle modes. this delay is required for the cpu to prepare for execution. instruction execution resumes on the first clock cycle following this delay. 3.5.2 exit by wdt time-out a wdt time-out will cause different actions depending on which power-managed mode the device is in when the time-out occurs. if the device is not executing code (all idle modes and sleep mode), the time-out will result in an exit from the power-managed mode (see section 3.2 ?run modes? and section 3.3 ?sleep mode? ). if the device is executing code (all run modes), the time-out will result in a wdt reset (see section 19.2 ?watchdog timer (wdt)? ). the wdt timer and postscaler are cleared by executing a sleep or clrwdt instruction, the loss of a currently selected clock source (if the fail-safe clock monitor is enabled) and modifying the ircf bits in the osccon register if the internal oscillator block is the device clock source. 3.5.3 exit by reset normally, the device is held in reset by the oscillator start-up timer (ost) until the primary clock becomes ready. at that time, the osts bit is set and the device begins executing code. if the internal oscillator block is the new clock source, the iofs bit is set instead. the exit delay time from reset to the start of code execution depends on both the clock sources before and after the wake-up and the type of oscillator if the new clock source is the primary clock. exit delays are summarized in table 3-2. code execution can begin before the primary clock becomes ready. if either the two-speed start-up (see section 19.3 ?two-speed start-up? ) or fail-safe clock monitor (see section 19.4 ?fail-safe clock monitor? ) is enabled, the device may begin execution as soon as the reset source has cleared. execution is clocked by the intosc multiplexer driven by the internal oscillator block. execution is clocked by the internal oscillator block until either the primary clock becomes ready or a power-managed mode is entered before the primary clock becomes ready; the primary clock is then shut down.
pic18f1230/1330 ds39758b-page 32 advance information ? 2006 microchip technology inc. 3.5.4 exit without an oscillator start-up delay certain exits from power-managed modes do not invoke the ost at all. there are two cases: ? pri_idle mode, where the primary clock source is not stopped; and ? the primary clock source is not any of the lp, xt, hs or hspll modes. in these instances, the primary clock source either does not require an oscillator start-up delay since it is already running (pri_idle), or normally does not require an oscillator start-up delay (rc, ec and intio oscillator modes). however, a fixed delay of interval t csd following the wake event is still required when leaving sleep and idle modes to allow the cpu to prepare for execution. instruction execution resumes on the first clock cycle following this delay. table 3-2: exit delay on wake-up by reset from sleep mode or any idle mode (by clock sources) clock source before wake-up clock source after wake-up exit delay clock ready status bit (osccon) primary device clock (pri_idle mode) lp, xt, hs t csd (1) osts hspll ec, rc intosc (2) iofs t1osc lp, xt, hs t ost (3) osts hspll t ost + t rc (3) ec, rc t csd (1) intosc (1) t iobst (4) iofs intosc (3) lp, xt, hs t ost (4) osts hspll t ost + t rc (3) ec, rc t csd (1) intosc (1) none iofs none (sleep mode) lp, xt, hs t ost (3) osts hspll t ost + t rc (3) ec, rc t csd (1) intosc (1) t iobst (4) iofs note 1: t csd (parameter 38) is a required delay when waking from sleep and all idle modes and runs concurrently with any other required delays (see section 3.4 ?idle modes? ). on reset, intosc defaults to 1 mhz. 2: includes both the intosc 8 mhz source and postscaler derived frequencies. 3: t ost is the oscillator start-up timer (parameter 32). t rc is the pll lock-out timer (parameter f12); it is also designated as t pll . 4: execution continues during t iobst (parameter 39), the intosc stabilization period.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 33 4.0 reset the pic18f1230/1330 devices differentiate between various kinds of reset: a) power-on reset (por) b) mclr reset during normal operation c) mclr reset during power-managed modes d) watchdog timer (wdt) reset (during execution) e) programmable brown-out reset (bor) f) reset instruction g) stack full reset h) stack underflow reset this section discusses resets generated by mclr , por and bor and covers the operation of the various start-up timers. stack reset events are covered in section 5.1.2.4 ?stack full and underflow resets? . wdt resets are covered in section 19.2 ?watchdog timer (wdt)? . a simplified block diagram of the on-chip reset circuit is shown in figure 4-1. 4.1 rcon register device reset events are tracked through the rcon register (register 4-1). the lower five bits of the register indicate that a specific reset event has occurred. in most cases, these bits can only be cleared by the event and must be set by the application after the event. the state of these flag bits, taken together, can be read to indicate the type of reset that just occurred. this is described in more detail in section 4.6 ?reset state of registers? . the rcon register also has control bits for setting interrupt priority (ipen) and software control of the bor (sboren). interrupt priority is discussed in section 10.0 ?interrupts? . bor is covered in section 4.4 ?brown-out reset (bor)? . figure 4-1: simplified block diagram of on-chip reset circuit external reset mclr v dd osc1 wdt time-out v dd rise detect ost/pwrt intrc (1) por pulse ost 10-bit ripple counter pwrt 11-bit ripple counter enable ost (2) enable pwrt note 1: this is the intrc source from the internal oscillator bl ock and is separate from the rc oscillator of the clki pin. 2: see table 4-2 for time-out situations. brown-out reset boren reset instruction stack pointer stack full/underflow reset sleep ( )_idle 1024 cycles 65.5 ms 32 s mclre s r q chip_reset
pic18f1230/1330 ds39758b-page 34 advance information ? 2006 microchip technology inc. register 4-1: rcon: reset control register r/w-0 r/w-1 (1) u-0 r/w-1 r-1 r-1 r/w-0 (2) r/w-0 ipen sboren ?ri to pd por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6 sboren: bor software enable bit (1) if boren1:boren0 = 01 : 1 = bor is enabled 0 = bor is disabled if boren1:boren0 = 00 , 10 or 11 : bit is disabled and read as ? 0 ?. bit 5 unimplemented: read as ? 0 ? bit 4 ri : reset instruction flag bit 1 = the reset instruction was not executed (set by firmware only) 0 = the reset instruction was executed causing a device reset (must be set in software after a brown-out reset occurs) bit 3 to : watchdog time-out flag bit 1 = set by power-up, clrwdt instruction or sleep instruction 0 = a wdt time-out occurred bit 2 pd : power-down detection flag bit 1 = set by power-up or by the clrwdt instruction 0 = set by execution of the sleep instruction bit 1 por : power-on reset status bit (2) 1 = a power-on reset has not occurred (set by firmware only) 0 = a power-on reset occurred (must be set in software after a power-on reset occurs) bit 0 bor : brown-out reset status bit 1 = a brown-out reset has not occurred (set by firmware only) 0 = a brown-out reset occurred (must be set in software after a brown-out reset occurs) note 1: if sboren is enabled, its reset state is ? 1 ?; otherwise, it is ? 0 ?. 2: the actual reset value of por is determined by the type of device reset. see the notes following this register and section 4.6 ?reset state of registers? for additional information. note 1: it is recommended that the por bit be set after a power-on reset has been detected so that subsequent power-on resets may be detected. 2: brown-out reset is said to have occurred when bor is ? 0 ? and por is ? 1 ? (assuming that por was set to ? 1 ? by software immediately after a power-on reset).
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 35 4.2 master clear (mclr ) the mclr pin provides a method for triggering an external reset of the device. a reset is generated by holding the pin low. these devices have a noise filter in the mclr reset path which detects and ignores small pulses. the mclr pin is not driven low by any internal resets, including the wdt. in pic18f1230/1330 devices, the mclr input can be disabled with the mclre configuration bit. when mclr is disabled, the pin becomes a digital input. see section 9.1 ?porta, trisa and lata registers? for more information. 4.3 power-on reset (por) a power-on reset pulse is generated on-chip whenever v dd rises above a certain threshold. this allows the device to start in the initialized state when v dd is adequate for operation. to take advantage of the por circuitry, tie the mclr pin through a resistor (1 k to 10 k ) to v dd . this will eliminate external rc components usually needed to create a power-on reset delay. a minimum rise rate for v dd is specified (parameter d004). for a slow rise time, see figure 4-2. when the device starts normal operation (i.e., exits the reset condition), device operating parameters (voltage, frequency, temperature, etc.) must be met to ensure operation. if these conditions are not met, the device must be held in reset until the operating conditions are met. por events are captured by the por bit (rcon<1>). the state of the bit is set to ? 0 ? whenever a power-on reset occurs; it does not change for any other reset event. por is not reset to ? 1 ? by any hardware event. to capture multiple events, the user manually resets the bit to ? 1 ? in software following any power-on reset. figure 4-2: external power-on reset circuit (for slow v dd power-up) note 1: external power-on reset circuit is required only if the v dd power-up slope is too slow. the diode d helps discharge the capacitor quickly when v dd powers down. 2: r < 40 k is recommended to make sure that the voltage drop across r does not violate the device?s electrical specification. 3: r1 1 k will limit any current flowing into mclr from external capacitor c, in the event of mclr /v pp pin breakdown, due to electrostatic discharge (esd) or electrical overstress (eos). c r1 r d v dd mclr pic18fxxxx v dd
pic18f1230/1330 ds39758b-page 36 advance information ? 2006 microchip technology inc. 4.4 brown-out reset (bor) pic18f1230/1330 devices implement a bor circuit that provides the user with a number of configuration and power-saving options. the bor is controlled by the borv1:borv0 and boren1:boren0 configuration bits. there are a total of four bor configurations which are summarized in table 4-1. the bor threshold is set by the borv1:borv0 bits. if bor is enabled (any values of boren1:boren0 except ? 00 ?), any drop of v dd below v bor (parameter d005) for greater than t bor (parameter 35) will reset the device. a reset may or may not occur if v dd falls below v bor for less than t bor . the chip will remain in brown-out reset until v dd rises above v bor . if the power-up timer is enabled, it will be invoked after v dd rises above v bor ; it then will keep the chip in reset for an additional time delay, t pwrt (parameter 33). if v dd drops below v bor while the power-up timer is running, the chip will go back into a brown-out reset and the power-up timer will be initialized. once v dd rises above v bor , the power-up timer will execute the additional time delay. bor and the power-on timer (pwrt) are independently configured. enabling bor reset does not automatically enable the pwrt. 4.4.1 software enabled bor when boren1:boren0 = 01 , the bor can be enabled or disabled by the user in software. this is done with the control bit, sboren (rcon<6>). setting sboren enables the bor to function as previously described. clearing sboren disables the bor entirely. the sboren bit operates only in this mode; otherwise it is read as ? 0 ?. placing the bor under software control gives the user the additional flexibility of tailoring the application to its environment without having to reprogram the device to change bor configuration. it also allows the user to tailor device power consumption in software by eliminating the incremental current that the bor consumes. while the bor current is typically very small, it may have some impact in low-power applications. 4.4.2 detecting bor when brown-out reset is enabled, the bor bit always resets to ? 0 ? on any brown-out reset or power-on reset event. this makes it difficult to determine if a brown-out reset event has occurred just by reading the state of bor alone. a more reliable method is to simultaneously check the state of both por and bor . this assumes that the por bit is reset to ? 1 ? in software immediately after any power-on reset event. if bor is ? 0 ? while por is ? 1 ?, it can be reliably assumed that a brown-out reset event has occurred. 4.4.3 disabling bor in sleep mode when boren1:boren0 = 10 , the bor remains under hardware control and operates as previously described. whenever the device enters sleep mode, however, the bor is automatically disabled. when the device returns to any other operating mode, bor is automatically re-enabled. this mode allows for applications to recover from brown-out situations, while actively executing code, when the device requires bor protection the most. at the same time, it saves additional power in sleep mode by eliminating the small incremental bor current. table 4-1: bor configurations note: even when bor is under software control, the bor reset voltage level is still set by the borv1:borv0 configuration bits. it cannot be changed in software. bor configuration status of sboren (rcon<6>) bor operation boren1 boren0 00 unavailable bor disabled; must be enabled by reprogramming the configuration bits. 01 available bor enabled in software; operation controlled by sboren. 10 unavailable bor enabled in hardware in run and idle modes, disabled during sleep mode. 11 unavailable bor enabled in hardware; must be disabled by reprogramming the configuration bits.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 37 4.5 device reset timers pic18f1230/1330 devices incorporate three separate on-chip timers that help regulate the power-on reset process. their main function is to ensure that the device clock is stable before code is executed. these timers are: ? power-up timer (pwrt) ? oscillator start-up timer (ost) ? pll lock time-out 4.5.1 power-up timer (pwrt) the power-up timer (pwrt) of pic18f1230/1330 devices is an 11-bit counter which uses the intrc source as the clock input. this yields an approximate time interval of 2048 x 32 s = 65.6 ms. while the pwrt is counting, the device is held in reset. the power-up time delay depends on the intrc clock and will vary from chip to chip due to temperature and process variation. see dc parameter 33 for details. the pwrt is enabled by clearing the pwrten configuration bit. 4.5.2 oscillator start-up timer (ost) the oscillator start-up timer (ost) provides a 1024 oscillator cycle (from osc1 input) delay after the pwrt delay is over (parameter 33). this ensures that the crystal oscillator or resonator has started and stabilized. the ost time-out is invoked only for xt, lp, hs and hspll modes and only on power-on reset, or on exit from most power-managed modes. 4.5.3 pll lock time-out with the pll enabled in its pll mode, the time-out sequence following a power-on reset is slightly different from other oscillator modes. a separate timer is used to provide a fixed time-out that is sufficient for the pll to lock to the main oscillator frequency. this pll lock time-out (t pll ) is typically 2 ms and follows the oscillator start-up time-out. 4.5.4 time-out sequence on power-up, the time-out sequence is as follows: 1. after the por pulse has cleared, pwrt time-out is invoked (if enabled). 2. then, the ost is activated. the total time-out will vary based on oscillator configuration and the status of the pwrt. figure 4-3, figure 4-4, figure 4-5, figure 4-6 and figure 4-7 all depict time-out sequences on power-up, with the power-up timer enabled and the device operating in hs oscillator mode. figures 4-3 through 4-6 also apply to devices operating in xt or lp modes. for devices in rc mode and with the pwrt disabled, there will be no time-out at all. since the time-outs occur from the por pulse, if mclr is kept low long enough, all time-outs will expire. bringing mclr high will begin execution immediately (figure 4-5). this is useful for testing purposes or to synchronize more than one pic18fxxxx device operating in parallel. table 4-2: time-out in various situations oscillator configuration power-up (2) and brown-out reset exit from power-managed mode pwrten = 0 pwrten = 1 hspll 66 ms (1) + 1024 t osc + 2 ms (2) 1024 t osc + 2 ms (2) 1024 t osc + 2 ms (2) hs, xt, lp 66 ms (1) + 1024 t osc 1024 t osc 1024 t osc ec, ecio 66 ms (1) ?? rc, rcio 66 ms (1) ?? intio1, intio2 66 ms (1) ?? note 1: 66 ms (65.5 ms) is the nominal power-up timer (pwrt) delay. 2: 2 ms is the nominal time required for the pll to lock.
pic18f1230/1330 ds39758b-page 38 advance information ? 2006 microchip technology inc. figure 4-3: time-out sequence on power-up (mclr tied to v dd , v dd rise < t pwrt ) figure 4-4: time-out sequence on power-up (mclr not tied to v dd ): case 1 figure 4-5: time-out sequence on power-up (mclr not tied to v dd ): case 2 t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset v dd mclr internal por pwrt time-out ost time-out internal reset t pwrt t ost
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 39 figure 4-6: slow rise time (mclr tied to v dd , v dd rise > t pwrt ) figure 4-7: time-out sequence on por w/pll enabled (mclr tied to v dd ) v dd mclr internal por pwrt time-out ost time-out internal reset 0v 5v t pwrt t ost t pwrt t ost v dd mclr internal por pwrt time-out ost time-out internal reset pll time-out t pll note: t ost = 1024 clock cycles. t pll 2 ms max. first three stages of the pwrt timer.
pic18f1230/1330 ds39758b-page 40 advance information ? 2006 microchip technology inc. 4.6 reset state of registers most registers are unaffected by a reset. their status is unknown on por and unchanged by all other resets. the other registers are forced to a ?reset state? depending on the type of reset that occurred. most registers are not affected by a wdt wake-up, since this is viewed as the resumption of normal oper- ation. status bits from the rcon register, ri , to , pd , por and bor , are set or cleared differently in different reset situations, as indicated in table 4-3. these bits are used in software to determine the nature of the reset. table 4-4 describes the reset states for all of the special function registers. these are categorized by power-on and brown-out resets, master clear and wdt resets and wdt wake-ups. table 4-3: status bits, their significance and the initialization condition for rcon register condition program counter rcon register stkptr register sboren ri to pd por bor stkful stkunf power-on reset 0000h 1 11100 0 0 reset instruction 0000h u (2) 0uuuu u u brown-out reset 0000h u (2) 111u0 u u mclr during power-managed run modes 0000h u (2) u1uuu u u mclr during power-managed idle modes and sleep mode 0000h u (2) u10uu u u wdt time-out during full power or power-managed run mode 0000h u (2) u0uuu u u mclr during full power execution 0000h u (2) uuuuu u u stack full reset (stvren = 1 ) 0000h u (2) uuuuu 1 u stack underflow reset (stvren = 1 ) 0000h u (2) uuuuu u 1 stack underflow error (not an actual reset, stvren = 0 ) 0000h u (2) uuuuu u 1 wdt time-out during power-managed idle or sleep modes pc + 2 u (2) u00uu u u interrupt exit from power-managed modes pc + 2 (1) u (2) uu0uu u u legend: u = unchanged note 1: when the wake-up is due to an interrupt and the gieh or giel bit is set, the pc is loaded with the interrupt vector (008h or 0018h). 2: reset state is ? 1 ? for por and unchanged for all other resets when software bor is enabled (boren1:boren0 configuration bits = 01 and sboren = 1 ); otherwise, the reset state is ? 0 ?.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 41 table 4-4: initialization conditions for all registers register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt tosu 1230 1330 ---0 0000 ---0 0000 ---0 uuuu (3) tosh 1230 1330 0000 0000 0000 0000 uuuu uuuu (3) tosl 1230 1330 0000 0000 0000 0000 uuuu uuuu (3) stkptr 1230 1330 00-0 0000 uu-0 0000 uu-u uuuu (3) pclatu 1230 1330 ---0 0000 ---0 0000 ---u uuuu pclath 1230 1330 0000 0000 0000 0000 uuuu uuuu pcl 1230 1330 0000 0000 0000 0000 pc + 2 (2) tblptru 1230 1330 --00 0000 --00 0000 --uu uuuu tblptrh 1230 1330 0000 0000 0000 0000 uuuu uuuu tblptrl 1230 1330 0000 0000 0000 0000 uuuu uuuu tablat 1230 1330 0000 0000 0000 0000 uuuu uuuu prodh 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu prodl 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu intcon 1230 1330 0000 000x 0000 000u uuuu uuuu (1) intcon2 1230 1330 1111 1111 1111 1111 uuuu uuuu (1) intcon3 1230 1330 1100 0000 1100 0000 uuuu uuuu (1) indf0 1230 1330 n/a n/a n/a postinc0 1230 1330 n/a n/a n/a postdec0 1230 1330 n/a n/a n/a preinc0 1230 1330 n/a n/a n/a plusw0 1230 1330 n/a n/a n/a fsr0h 1230 1330 ---- 0000 ---- 0000 ---- uuuu fsr0l 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu wreg 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu indf1 1230 1330 n/a n/a n/a postinc1 1230 1330 n/a n/a n/a postdec1 1230 1330 n/a n/a n/a preinc1 1230 1330 n/a n/a n/a plusw1 1230 1330 n/a n/a n/a fsr1h 1230 1330 ---- 0000 ---- 0000 ---- uuuu fsr1l 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu bsr 1230 1330 ---- 0000 ---- 0000 ---- uuuu legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: reset condition of pwmen bits depends on the pwmpin configuration bit of config3l.
pic18f1230/1330 ds39758b-page 42 advance information ? 2006 microchip technology inc. indf2 1230 1330 n/a n/a n/a postinc2 1230 1330 n/a n/a n/a postdec2 1230 1330 n/a n/a n/a preinc2 1230 1330 n/a n/a n/a plusw2 1230 1330 n/a n/a n/a fsr2h 1230 1330 ---- 0000 ---- 0000 ---- uuuu fsr2l 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu status 1230 1330 ---x xxxx ---u uuuu ---u uuuu tmr0h 1230 1330 0000 0000 0000 0000 uuuu uuuu tmr0l 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu t0con 1230 1330 1111 1111 1111 1111 uuuu uuuu osccon 1230 1330 0100 q000 0100 q000 uuuu uuqu lvdcon 1230 1330 --00 0101 --00 0101 --uu uuuu wdtcon 1230 1330 ---- ---0 ---- ---0 ---- ---u rcon (4) 1230 1330 0q-1 11q0 0q-q qquu uq-u qquu tmr1h 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu tmr1l 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu t1con 1230 1330 0000 0000 u0uu uuuu uuuu uuuu adresh 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu adresl 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu adcon0 1230 1330 0--- 0000 0--- 0000 u--- uuuu adcon1 1230 1330 ---0 1111 ---0 1111 ---u uuuu adcon2 1230 1330 0-00 0000 0-00 0000 u-uu uuuu baudcon 1230 1330 01-0 0-00 01-0 0-00 --uu uuuu cvrcon 1230 1330 0-00 0000 0-00 0000 u-uu uuuu cmcon 1230 1330 000- -000 000- -000 uuu- -uuu spbrgh 1230 1330 0000 0000 0000 0000 uuuu uuuu spbrg 1230 1330 0000 0000 0000 0000 uuuu uuuu rcreg 1230 1330 0000 0000 0000 0000 uuuu uuuu txreg 1230 1330 0000 0000 0000 0000 uuuu uuuu txsta 1230 1330 0000 0010 0000 0010 uuuu uuuu rcsta 1230 1330 0000 000x 0000 000x uuuu uuuu table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: reset condition of pwmen bits depends on the pwmpin configuration bit of config3l.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 43 eeadr 1230 1330 0000 0000 0000 0000 uuuu uuuu eedata 1230 1330 0000 0000 0000 0000 uuuu uuuu eecon2 1230 1330 0000 0000 0000 0000 0000 0000 eecon1 1230 1330 xx-0 x000 uu-0 u000 uu-0 u000 ipr3 1230 1330 ---0 ---- ---0 ---- ---u ---- pir3 1230 1330 ---0 ---- ---0 ---- ---u ---- pie3 1230 1330 ---0 ---- ---0 ---- ---u ---- ipir2 1230 1330 1--1 -1-- 1--1 -1-- u--u -u-- pir2 1230 1330 0--0 -0-- 0--0 -0-- u--u -u-- (1) pie2 1230 1330 0--0 -0-- 0--0 -0-- u--u -u-- ipr1 1230 1330 -111 1111 -111 1111 -uuu uuuu pir1 1230 1330 -000 0000 -000 0000 -uuu uuuu (1) pie1 1230 1330 -000 0000 -000 0000 -uuu uuuu osctune 1230 1330 00-0 0000 00-0 0000 uu-u uuuu ptcon0 1230 1330 0000 0000 uuuu uuuu uuuu uuuu ptcon1 1230 1330 00-- ---- 00-- ---- uu-- ---- ptmrl 1230 1330 0000 0000 0000 0000 uuuu uuuu ptmrh 1230 1330 ---- 0000 ---- 0000 ---- uuuu ptperl 1230 1330 1111 1111 1111 1111 uuuu uuuu ptperh 1230 1330 ---- 1111 ---- 1111 ---- uuuu trisb 1230 1330 1111 1111 1111 1111 uuuu uuuu trisa 1230 1330 1111 1111 (5) 1111 1111 (5) uuuu uuuu (5) pdc0l 1230 1330 0000 0000 0000 0000 uuuu uuuu pdc0h 1230 1330 --00 0000 --00 0000 --uu uuuu pdc1l 1230 1330 0000 0000 0000 0000 uuuu uuuu pdc1h 1230 1330 --00 0000 --00 0000 --uu uuuu pdc2l 1230 1330 0000 0000 0000 0000 uuuu uuuu pdc2h 1230 1330 --00 0000 --00 0000 --uu uuuu fltconfig 1230 1330 0--- -000 0--- -000 u--- -uuu latb 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu lata 1230 1330 xxxx xxxx (5) uuuu uuuu (5) uuuu uuuu (5) sevtcmpl 1230 1330 0000 0000 0000 0000 uuuu uuuu table 4-4: initialization conditions for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: reset condition of pwmen bits depends on the pwmpin configuration bit of config3l.
pic18f1230/1330 ds39758b-page 44 advance information ? 2006 microchip technology inc. sevtcmph 1230 1330 ---- 0000 ---- 0000 ---- uuuu pwmcon0 1230 1330 -100 -000 (6) -100 -000 (6) -uuu -uuu (6) -000 -000 (6) -000 -000 (6) -uuu -uuu (6) pwmcon1 1230 1330 0000 0-00 0000 0-00 uuuu u-uu dtcon 1230 1330 0000 0000 0000 0000 uuuu uuuu ovdcond 1230 1330 --11 1111 --11 1111 --uu uuuu ovdcons 1230 1330 --00 0000 --00 0000 --uu uuuu portb 1230 1330 xxxx xxxx uuuu uuuu uuuu uuuu porta 1230 1330 xx0x 0000 (5) uu0u 0000 (5) uuuu uuuu (5) table 4-4: initialization conditi ons for all registers (continued) register applicable devices power-on reset, brown-out reset mclr resets, wdt reset, reset instruction, stack resets wake-up via wdt or interrupt legend: u = unchanged, x = unknown, - = unimplemented bit, read as ? 0 ?, q = value depends on condition note 1: one or more bits in the intconx or pirx registers will be affected (to cause wake-up). 2: when the wake-up is due to an interrupt and the giel or gieh bit is set, the pc is loaded with the interrupt vector (0008h or 0018h). 3: when the wake-up is due to an interrupt and the giel or gieh bit is set, the tosu, tosh and tosl are updated with the current value of the pc. the stkptr is modified to point to the next location in the hardware stack. 4: see table 4-3 for reset value for specific condition. 5: bits 6 and 7 of porta, lata and trisa are enabled depending on the oscillator mode selected. when not enabled as porta pins, they are disabled and read ? 0 ?. 6: reset condition of pwmen bits depends on the pwmpin configuration bit of config3l.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 45 5.0 memory organization there are three types of memory in pic18 enhanced microcontroller devices: ? program memory ? data ram ? data eeprom as harvard architecture devices, the data and program memories use separate busses; this allows for concurrent access of the two memory spaces. the data eeprom, for practical purposes, can be regarded as a peripheral device, since it is addressed and accessed through a set of control registers. additional detailed information on the operation of the flash program memory is provided in section 6.0 ?flash program memory? . data eeprom is discussed separately in section 7.0 ?data eeprom memory? . 5.1 program memory organization pic18 microcontrollers implement a 21-bit program counter, which is capable of addressing a 2-mbyte program memory space. accessing a location between the upper boundary of the physically implemented memory and the 2-mbyte address will return all ? 0 ?s (a nop instruction). the pic18f1230 has 4 kbytes of flash memory and can store up to 2,048 single-word instructions. the pic18f1330 has 8 kbytes of flash memory and can store up to 4,096 single-word instructions. pic18 devices have two interrupt vectors. the reset vector address is at 0000h and the interrupt vector addresses are at 0008h and 0018h. the program memory maps for pic18f1230 and pic18f1330 devices are shown in figure 5-1. figure 5-1: program memory map and stack for pic18f1230/1330 devices pc<20:0> stack level 1 ? stack level 31 reset vector low priority interrupt vector ? ? call,rcall,return retfie,retlw 21 0000h 0018h on-chip program memory high priority interrupt vector 0008h user memory space 1fffffh 1000h 0fffh read ? 0 ? 200000h pc<20:0> stack level 1 ? stack level 31 reset vector low priority interrupt vector ? ? call,rcall,return retfie,retlw 21 0000h 0018h 2000h 1fffh on-chip program memory high priority interrupt vector 0008h user memory space read ? 0 ? 1fffffh 200000h pic18f1230 pic18f1330
pic18f1230/1330 ds39758b-page 46 advance information ? 2006 microchip technology inc. 5.1.1 program counter the program counter (pc) specifies the address of the instruction to fetch for execution. the pc is 21 bits wide and is contained in three separate 8-bit registers. the low byte, known as the pcl register, is both readable and writable. the high byte, or pch register, contains the pc<15:8> bits; it is not directly readable or writable. updates to the pch register are performed through the pclath register. the upper byte is called pcu. this register contains the pc<20:16> bits; it is also not directly readable or writable. updates to the pcu register are performed through the pclatu register. the contents of pclath and pclatu are transferred to the program counter by any operation that writes to the pcl. similarly, the upper two bytes of the program counter are transferred to pclath and pclatu by an operation that reads the pcl. this is useful for computed offsets to the pc (see section 5.1.4.1 ?computed goto? ). the pc addresses bytes in the program memory. to prevent the pc from becoming misaligned with word instructions, the least significant bit of pcl is fixed to a value of ? 0 ?. the pc increments by 2 to address sequential instructions in the program memory. the call , rcall , goto and program branch instructions write to the program counter directly. for these instructions, the contents of pclath and pclatu are not transferred to the program counter. 5.1.2 return address stack the return address stack allows any combination of up to 31 program calls and interrupts to occur. the pc is pushed onto the stack when a call or rcall instruction is executed or an interrupt is acknowledged. the pc value is pulled off the stack on a return , retlw or a retfie instruction. pclatu and pclath are not affected by any of the return or call instructions. the stack operates as a 31-word by 21-bit ram and a 5-bit stack pointer, stkptr. the stack space is not part of either program or data space. the stack pointer is readable and writable and the address on the top of the stack is readable and writable through the top-of- stack special function registers. data can also be pushed to, or popped from the stack, using these registers. a call type instruction causes a push onto the stack; the stack pointer is first incremented and the location pointed to by the stack pointer is written with the contents of the pc (already pointing to the instruction following the call ). a return type instruction causes a pop from the stack; the contents of the location pointed to by the stkptr are transferred to the pc and then the stack pointer is decremented. the stack pointer is initialized to ? 00000 ? after all resets. there is no ram associated with the location corresponding to a stack pointer value of ? 00000 ?; this is only a reset value. status bits indicate if the stack is full, has overflowed or has underflowed. 5.1.2.1 top-of-stack access only the top of the return address stack (tos) is readable and writable. a set of three registers, tosu:tosh:tosl, hold the contents of the stack location pointed to by the stkptr register (figure 5-2). this allows users to implement a software stack if necessary. after a call , rcall or interrupt, the software can read the pushed value by reading the tosu:tosh:tosl registers. these values can be placed on a user-defined software stack. at return time, the software can return these values to tosu:tosh:tosl and do a return. the user must disable the global interrupt enable bits while accessing the stack to prevent inadvertent stack corruption. figure 5-2: return address stack and associated registers 00011 001a34h 11111 11110 11101 00010 00001 00000 00010 return address stack <20:0> to p - o f - st a c k 000d58h stkptr<4:0> top-of-stack registers stack pointer tosl tosh tosu 34h 1ah 00h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 47 5.1.2.2 return stack pointer (stkptr) the stkptr register (register 5-1) contains the stack pointer value, the stkful (stack full) status bit and the stkunf (stack underflow) status bits. the value of the stack pointer can be 0 through 31. the stack pointer increments before values are pushed onto the stack and decrements after values are popped off the stack. on reset, the stack pointer value will be zero. the user may read and write the stack pointer value. this feature can be used by a real-time operating system (rtos) for return stack maintenance. after the pc is pushed onto the stack 31 times (without popping any values off the stack), the stkful bit is set. the stkful bit is cleared by software or by a por. the action that takes place when the stack becomes full depends on the state of the stvren (stack overflow reset enable) configuration bit. (refer to section 19.1 ?configuration bits? for a description of the device configuration bits.) if stvren is set (default), the 31st push will push the (pc + 2) value onto the stack, set the stkful bit and reset the device. the stkful bit will remain set and the stack pointer will be set to zero. if stvren is cleared, the stkful bit will be set on the 31st push and the stack pointer will increment to 31. any additional pushes will not overwrite the 31st push and stkptr will remain at 31. when the stack has been popped enough times to unload the stack, the next pop will return a value of zero to the pc and sets the stkunf bit, while the stack pointer remains at zero. the stkunf bit will remain set until cleared by software or until a por occurs. 5.1.2.3 push and pop instructions since the top-of-stack is readable and writable, the ability to push values onto the stack and pull values off the stack, without disturbing normal program execu- tion, is a desirable feature. the pic18 instruction set includes two instructions, push and pop , that permit the tos to be manipulated under software control. tosu, tosh and tosl can be modified to place data or a return address on the stack. the push instruction places the current pc value onto the stack. this increments the stack pointer and loads the current pc value onto the stack. the pop instruction discards the current tos by decrementing the stack pointer. the previous value pushed onto the stack then becomes the tos value. note: returning a value of zero to the pc on an underflow has the effect of vectoring the program to the reset vector, where the stack conditions can be verified and appropriate actions can be taken. this is not the same as a reset, as the contents of the sfrs are not affected. register 5-1: stkptr: stack pointer register r/c-0 r/c-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 stkful (1) stkunf (1) ? sp4 sp3 sp2 sp1 sp0 bit 7 bit 0 legend: c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 stkful: stack full flag bit (1) 1 = stack became full or overflowed 0 = stack has not become full or overflowed bit 6 stkunf: stack underflow flag bit (1) 1 = stack underflow occurred 0 = stack underflow did not occur bit 5 unimplemented: read as ? 0 ? bit 4-0 sp4:sp0: stack pointer location bits note 1: bit 7 and bit 6 are cleared by user software or by a por.
pic18f1230/1330 ds39758b-page 48 advance information ? 2006 microchip technology inc. 5.1.2.4 stack full and underflow resets device resets on stack overflow and stack underflow conditions are enabled by setting the stvren bit in configuration register 4l. when stvren is set, a full or underflow will set the appropriate stkful or stkunf bit and then cause a device reset. when stvren is cleared, a full or underflow condition will set the appropriate stkful or stkunf bit but not cause a device reset. the stkful or stkunf bit is cleared by the user software or a power-on reset. 5.1.3 fast register stack a fast register stack is provided for the status, wreg and bsr registers, to provide a ?fast return? option for interrupts. the stack for each register is only one level deep and is neither readable nor writable. it is loaded with the current value of the corresponding register when the processor vectors for an interrupt. all interrupt sources will push values into the stack registers. the values in the registers are then loaded back into their associated registers if the retfie, fast instruction is used to return from the interrupt. if both low and high priority interrupts are enabled, the stack registers cannot be used reliably to return from low priority interrupts. if a high priority interrupt occurs while servicing a low priority interrupt, the stack regis- ter values stored by the low priority interrupt will be overwritten. in these cases, users must save the key registers in software during a low priority interrupt. if interrupt priority is not used, all interrupts may use the fast register stack for returns from interrupt. if no interrupts are used, the fast register stack can be used to restore the status, wreg and bsr registers at the end of a subroutine call. to use the fast register stack for a subroutine call, a call label , fast instruction must be executed to save the status, wreg and bsr registers to the fast register stack. a return, fast instruction is then executed to restore these registers from the fast register stack. example 5-1 shows a source code example that uses the fast register stack during a subroutine call and return. example 5-1: fast register stack code example 5.1.4 look-up tables in program memory there may be programming situations that require the creation of data structures, or look-up tables, in program memory. for pic18 devices, look-up tables can be implemented in two ways: ? computed goto ? table reads 5.1.4.1 computed goto a computed goto is accomplished by adding an offset to the program counter. an example is shown in example 5-2. a look-up table can be formed with an addwf pcl instruction and a group of retlw nn instructions. the w register is loaded with an offset into the table before executing a call to that table. the first instruction of the called routine is the addwf pcl instruction. the next instruction executed will be one of the retlw nn instructions that returns the value ? nn ? to the calling function. the offset value (in wreg) specifies the number of bytes that the program counter should advance and should be multiples of 2 (lsb = 0 ). in this method, only one data byte may be stored in each instruction location and room on the return address stack is required. example 5-2: computed goto using an offset value 5.1.4.2 table reads and table writes a better method of storing data in program memory allows two bytes of data to be stored in each instruction location. look-up table data may be stored two bytes per program word by using table reads and writes. the table pointer (tblptr) register specifies the byte address and the table latch (tablat) register contains the data that is read from or written to program memory. data is transferred to or from program memory one byte at a time. table read and table write operations are discussed further in section 6.1 ?table reads and table writes? . call sub1, fast ;status, wreg, bsr ;saved in fast register ;stack ? ? sub1 ? ? return, fast ;restore values saved ;in fast register stack movf offset, w call table org nn00h table addwf pcl retlw nnh retlw nnh retlw nnh . . .
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 49 5.2 pic18 instruction cycle 5.2.1 clocking scheme the microcontroller clock input, whether from an internal or external source, is internally divided by four to generate four non-overlapping quadrature clocks (q1, q2, q3 and q4). internally, the program counter is incremented on every q1; the instruction is fetched from the program memory and latched into the instruc- tion register (ir) during q4. the instruction is decoded and executed during the following q1 through q4. the clocks and instruction execution flow are shown in figure 5-3. 5.2.2 instruction flow/pipelining an ?instruction cycle? consists of four q cycles: q1 through q4. the instruction fetch and execute are pipelined in such a manner that a fetch takes one instruction cycle, while the decode and execute take another instruction cycle. however, due to the pipelining, each instruction effectively executes in one cycle. if an instruction causes the program counter to change (e.g., goto ), then two cycles are required to complete the instruction (example 5-3). a fetch cycle begins with the program counter (pc) incrementing in q1. in the execution cycle, the fetched instruction is latched into the instruction register (ir) in cycle q1. this instruction is then decoded and executed during the q2, q3 and q4 cycles. data memory is read during q2 (operand read) and written during q4 (destination write). figure 5-3: clock/ instruction cycle example 5-3: instruction pipeline flow q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 q1 q2 q3 q4 pc osc2/clko (rc mode) pc pc + 2 pc + 4 fetch inst (pc) execute inst (pc ? 2) fetch inst (pc + 2) execute inst (pc) fetch inst (pc + 4) execute inst (pc + 2) internal phase clock all instructions are single cycle, except for any program branches. these take two cycles since the fetch instruction is ?flushed? from the pipeline while the new instruction is being fetched and then executed. t cy 0t cy 1t cy 2t cy 3t cy 4t cy 5 1. movlw 55h fetch 1 execute 1 2. movwf portb fetch 2 execute 2 3. bra sub_1 fetch 3 execute 3 4. bsf porta, bit3 (forced nop) fetch 4 flush ( nop ) 5. instruction @ address sub_1 fetch sub_1 execute sub_1
pic18f1230/1330 ds39758b-page 50 advance information ? 2006 microchip technology inc. 5.2.3 instructions in program memory the program memory is addressed in bytes. instructions are stored as two bytes or four bytes in program memory. the least significant byte of an instruction word is always stored in a program memory location with an even address (lsb = 0 ). to maintain alignment with instruction boundaries, the pc increments in steps of 2 and the lsb will always read ? 0 ? (see section 5.1.1 ?program counter? ). figure 5-4 shows an example of how instruction words are stored in the program memory. the call and goto instructions have the absolute program memory address embedded into the instruction. since instructions are always stored on word boundaries, the data contained in the instruction is a word address. the word address is written to pc<20:1>, which accesses the desired byte address in program memory. instruction #2 in figure 5-4 shows how the instruction, goto 0006h , is encoded in the program memory. program branch instructions, which encode a relative address offset, operate in the same manner. the offset value stored in a br anch instruction represents the number of single-word instructions that the pc will be offset by. section 21.0 ?instruction set summary? provides further details of the instruction set. figure 5-4: instructions in program memory 5.2.4 two-word instructions the standard pic18 instruction set has four two-word instructions: call , movff , goto and lsfr . in all cases, the second word of the instructions always has ? 1111 ? as its four most significant bits; the other 12 bits are literal data, usually a data memory address. the use of ? 1111 ? in the 4 msbs of an instruction specifies a special form of nop . if the instruction is executed in proper sequence ? immediately after the first word ? the data in the second word is accessed and used by the instruction sequence. if the first word is skipped for some reason and the second word is executed by itself, a nop is executed instead. this is necessary for cases when the two-word instruction is preceded by a conditional instruction that changes the pc. example 5-4 shows how this works. example 5-4: two-word instructions word address lsb = 1 lsb = 0 program memory byte locations 000000h 000002h 000004h 000006h instruction 1: movlw 055h 0fh 55h 000008h instruction 2: goto 0006h efh 03h 00000ah f0h 00h 00000ch instruction 3: movff 123h, 456h c1h 23h 00000eh f4h 56h 000010h 000012h 000014h note: see section 5.6 ?pic18 instruction execution and the extended instruc- tion set? for information on two-word instructions in the extended instruction set. case 1: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; no, skip this word 1111 0100 0101 0110 ; execute this word as a nop 0010 0100 0000 0000 addwf reg3 ; continue code case 2: object code source code 0110 0110 0000 0000 tstfsz reg1 ; is ram location 0? 1100 0001 0010 0011 movff reg1, reg2 ; yes, execute this word 1111 0100 0101 0110 ; 2nd word of instruction 0010 0100 0000 0000 addwf reg3 ; continue code
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 51 5.3 data memory organization the data memory in pic18 devices is implemented as static ram. each register in the data memory has a 12-bit address, allowing up to 4096 bytes of data memory. the memory space is divided into as many as 16 banks that contain 256 bytes each; pic18f1230/ 1330 devices implement 1 bank. figure 5-5 shows the data memory organization for the pic18f1230/1330 devices. the data memory contains special function registers (sfrs) and general purpose registers (gprs). the sfrs are used for control and status of the controller and peripheral functions, while gprs are used for data storage and scratchpad operations in the user?s application. any read of an unimplemented location will read as ? 0 ?s. the instruction set and architecture allow operations across all banks. the entire data memory may be accessed by direct, indirect or indexed addressing modes. addressing modes are discussed later in this subsection. to ensure that commonly used registers (sfrs and select gprs) can be accessed in a single cycle, pic18 devices implement an access bank. this is a 256-byte memory space that provides fast access to sfrs and the lower portion of gpr bank 0 without using the bsr. section 5.3.2 ?access bank? provides a detailed description of the access ram. 5.3.1 bank select register (bsr) large areas of data memory require an efficient addressing scheme to make rapid access to any address possible. ideally, this means that an entire address does not need to be provided for each read or write operation. for pic18 devices, this is accomplished with a ram banking scheme. this divides the memory space into 16 contiguous banks of 256 bytes. depending on the instruction, each location can be addressed directly by its full 12-bit address, or an 8-bit low-order address and a 4-bit bank pointer. most instructions in the pic18 instruction set make use of the bank pointer, known as the bank select register (bsr). this sfr holds the four most significant bits of a location?s address; the instruction itself includes the eight least significant bits. only the four lower bits of the bsr are implemented (bsr3:bsr0). the upper four bits are unused; they will always read ? 0 ? and can- not be written to. the bsr can be loaded directly by using the movlb instruction. the value of the bsr indicates the bank in data memory. the 8 bits in the instruction show the location in the bank and can be thought of as an offset from the bank?s lower boundary. the relationship between the bsr?s value and the bank division in data memory is shown in figure 5-6. since up to 16 registers may share the same low-order address, the user must always be careful to ensure that the proper bank is selected before performing a data read or write. for example, writing what should be program data to an 8-bit address of f9h, while the bsr is 0fh, will end up resetting the program counter. while any bank can be selected, only those banks that are actually implemented can be read or written to. writes to unimplemented banks are ignored, while reads from unimplemented banks will return ? 0 ?s. even so, the status register will still be affected as if the operation was successful. the data memory map in figure 5-5 indicates which banks are implemented. in the core pic18 instruction set, only the movff instruction fully specifies the 12-bit address of the source and target registers. this instruction ignores the bsr completely when it executes. all other instructions include only the low-order address as an operand and must use either the bsr or the access bank to locate their target registers. note: the operation of some aspects of data memory are changed when the pic18 extended instruction set is enabled. see section 5.5 ?data memory and the extended instruction set? for more information.
pic18f1230/1330 ds39758b-page 52 advance information ? 2006 microchip technology inc. figure 5-5: data memory map for pic18f1230/1330 devices bank 0 bank 14 bank 15 data memory map bsr<3:0> = 0000 = 1111 080h 07fh f80h fffh 00h 7fh 80h ffh access bank when a = 0 : the bsr is ignored and the access bank is used. the first 128 bytes are general purpose ram (from bank 0). the second 128 bytes are special function registers (from bank 15). when a = 1 : the bsr specifies the bank used by the instruction. f7fh f00h effh 0ffh 000h access ram ffh 00h ffh 00h gpr sfr access ram high access ram low bank 1 (sfrs) = 0001 = 1110 unused read ?00h? to unused read ?00h?
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 53 figure 5-6: use of the bank select register (direct addressing) 5.3.2 access bank while the use of the bsr with an embedded 8-bit address allows users to address the entire range of data memory, it also means that the user must always ensure that the correct bank is selected. otherwise, data may be read from or written to the wrong location. this can be disastrous if a gpr is the intended target of an operation, but an sfr is written to instead. verifying and/or changing the bsr for each read or write to data memory can become very inefficient. to streamline access for the most commonly used data memory locations, the data memory is configured with an access bank, which allows users to access a mapped block of memory without specifying a bsr. the access bank consists of the first 128 bytes of memory (00h-7fh) in bank 0 and the last 128 bytes of memory (80h-ffh) in block 15. the lower half is known as the ?access ram? and is composed of gprs. the upper half is where the device?s sfrs are mapped. these two areas are mapped contiguously in the access bank and can be addressed in a linear fashion by an 8-bit address (figure 5-5). the access bank is used by core pic18 instructions that include the access ram bit (the ?a? parameter in the instruction). when ?a? is equal to ? 1 ?, the instruction uses the bsr and the 8-bit address included in the opcode for the data memory address. when ?a? is ? 0 ?, however, the instruction is forced to use the access bank address map; the current value of the bsr is ignored entirely. using this ?forced? addressing allows the instruction to operate on a data address in a single cycle without updating the bsr first. for 8-bit addresses of 80h and above, this means that users can evaluate and operate on sfrs more efficiently. the access ram below 80h is a good place for data values that the user might need to access rapidly, such as immediate computational results or common program variables. access ram also allows for faster and more code efficient context saving and switching of variables. the mapping of the access bank is slightly different when the extended instruction set is enabled (xinst configuration bit = 1 ). this is discussed in more detail in section 5.5.3 ?mapping the access bank in indexed literal offset addressing mode? . 5.3.3 general purpose register file pic18 devices may have banked memory in the gpr area. this is data ram which is available for use by all instructions. gprs start at the bottom of bank 0 (address 000h) and grow upwards towards the bottom of the sfr area. gprs are not initialized by a power-on reset and are unchanged on all other resets. note 1: the access ram bit of the instruction can be used to force an override of the sele cted bank (bsr<3:0>) to the registers of the access bank. 2: the movff instruction embeds the entire 12-bit address in the instruction. data memory bank select (2) 7 0 from opcode (2) 0000 000h 100h f00h e00h fffh bank 0 bank 14 bank 15 00h ffh 00h 00h ffh 00h ffh ffh bank 1 through bank 13 0000 11111111 7 0 bsr (1)
pic18f1230/1330 ds39758b-page 54 advance information ? 2006 microchip technology inc. 5.3.4 special function registers the special function registers (sfrs) are registers used by the cpu and peripheral modules for controlling the desired operation of the device. these registers are implemented as static ram. sfrs start at the top of data memory (fffh) and extend downward to occupy the top half of bank 15 (f80h to fffh). a list of these registers is given in table 5-1 and table 5-2. the sfrs can be classified into two sets: those associated with the ?core? device functionality (alu, resets and interrupts) and those related to the peripheral functions. the reset and interrupt registers are described in their respective chapters, while the alu?s status register is described later in this section. registers related to the operat ion of a peripheral feature are described in the chapter for that peripheral. the sfrs are typically distributed among the peripherals whose functions they control. unused sfr locations are unimplemented and read as ? 0 ?s. table 5-1: special function register map for pic18f1230/1330 devices address name address name address name address name fffh tosu fdfh indf2 (1) fbfh ? (2) f9fh ipr1 ffeh tosh fdeh postinc2 (1) fbeh ? (2) f9eh pir1 ffdh tosl fddh postdec2 (1) fbdh ? (2) f9dh pie1 ffch stkptr fdch preinc2 (1) fbch ? (2) f9ch ? (2) ffbh pclatu fdbh plusw2 (1) fbbh ? (2) f9bh osctune ffah pclath fdah fsr2h fbah ? (2) f9ah ptcon0 ff9h pcl fd9h fsr2l fb9h ? (2) f99h ptcon1 ff8h tblptru fd8h status fb8h baudcon f98h ptmrl ff7h tblptrh fd7h tmr0h fb7h ? (2) f97h ptmrh ff6h tblptrl fd6h tmr0l fb6h ? (2) f96h ptperl ff5h tablat fd5h t0con fb5h cvrcon f95h ptperh ff4h prodh fd4h ? (2) fb4h cmcon f94h ? (2) ff3h prodl fd3h osccon fb3h ? (2) f93h trisb ff2h intcon fd2h lvdcon fb2h ? (2) f92h trisa ff1h intcon2 fd1h wdtcon fb1h ? (2) f91h pdc0l ff0h intcon3 fd0h rcon fb0h spbrgh f90h pdc0h fefh indf0 (1) fcfh tmr1h fafh spbrg f8fh pdc1l feeh postinc0 (1) fceh tmr1l faeh rcreg f8eh pdc1h fedh postdec0 (1) fcdh t1con fadh txreg f8dh pdc2l fech preinc0 (1) fcch ? (2) fach txsta f8ch pdc2h febh plusw0 (1) fcbh ? (2) fabh rcsta f8bh fltconfig feah fsr0h fcah ? (2) faah ? (2) f8ah latb fe9h fsr0l fc9h ? (2) fa9h eeadr f89h lata fe8h wreg fc8h ? (2) fa8h eedata f88h sevtcmpl fe7h indf1 (1) fc7h ? (2) fa7h eecon2 (1) f87h sevtcmph fe6h postinc1 (1) fc6h ? (2) fa6h eecon1 f86h pwmcon0 fe5h postdec1 (1) fc5h ? (2) fa5h ipr3 f85h pwmcon1 fe4h preinc1 (1) fc4h adresh fa4h pir3 f84h dtcon fe3h plusw1 (1) fc3h adresl fa3h pie3 f83h ovdcond fe2h fsr1h fc2h adcon0 fa2h ipr2 f82h ovdcons fe1h fsr1l fc1h adcon1 fa1h pir2 f81h portb fe0h bsr fc0h adcon2 fa0h pie2 f80h porta note 1: this is not a physical register. 2: unimplemented registers are read as ? 0 ?.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 55 table 5-2: register file summary (pic18f1230/1330) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: tosu ? ? ? top-of-stack upper byte (tos<20:16>) ---0 0000 41, 46 tosh top-of-stack high byte (tos<15:8>) 0000 0000 41, 46 tosl top-of-stack low byte (tos<7:0>) 0000 0000 41, 46 stkptr stkful (5) stkunf (5) ? sp4 sp3 sp2 sp1 sp0 00-0 0000 41, 47 pclatu ? ? ? holding register for pc<20:16> ---0 0000 41, 46 pclath holding register for pc<15:8> 0000 0000 41, 46 pcl pc low byte (pc<7:0>) 0000 0000 41, 46 tblptru ? ? bit 21 program memory table pointer upper byte (tblptr<20:16>) --00 0000 41, 68 tblptrh program memory table pointer high byte (tblptr<15:8>) 0000 0000 41, 68 tblptrl program memory table pointer low byte (tblptr<7:0>) 0000 0000 41, 68 tablat program memory table latch 0000 0000 41, 68 prodh product register high byte xxxx xxxx 41, 79 prodl product register low byte xxxx xxxx 41, 79 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 0000 000x 41, 89 intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 1111 1111 41, 90 intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if 1100 0000 41, 91 indf0 uses contents of fsr0 to address data memory ? value of fsr0 not changed (not a physical register) n/a 41, 60 postinc0 uses contents of fsr0 to address data memory ? value of fsr0 post-incremented (not a physical register) n/a 41, 60 postdec0 uses contents of fsr0 to address data memory ? value of fsr0 post-decremented (not a physical register) n/a 41, 60 preinc0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) n/a 41, 60 plusw0 uses contents of fsr0 to address data memory ? value of fsr0 pre-incremented (not a physical register) ? value of fsr0 offset by w n/a 41, 60 fsr0h ? ? ? ? indirect data memory address pointer 0 high byte ---- 0000 41, 60 fsr0l indirect data memory address pointer 0 low byte xxxx xxxx 41, 60 wreg working register xxxx xxxx 41, 48 indf1 uses contents of fsr1 to address data memory ? value of fsr1 not changed (not a physical register) n/a 41, 60 postinc1 uses contents of fsr1 to address data memory ? value of fsr1 post-incremented (not a physical register) n/a 41, 60 postdec1 uses contents of fsr1 to address data memory ? value of fsr1 post-decremented (not a physical register) n/a 41, 60 preinc1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) n/a 41, 60 plusw1 uses contents of fsr1 to address data memory ? value of fsr1 pre-incremented (not a physical register) ? value of fsr1 offset by w n/a 41, 60 fsr1h ? ? ? ? indirect data memory address pointer 1 high byte ---- 0000 41, 60 fsr1l indirect data memory address pointer 1 low byte xxxx xxxx 41, 60 bsr ? ? ? ? bank select register ---- 0000 41, 51 indf2 uses contents of fsr2 to address data memory ? value of fsr2 not changed (not a physical register) n/a 42, 60 postinc2 uses contents of fsr2 to address data memory ? value of fsr2 post-incremented (not a physical register) n/a 42, 60 postdec2 uses contents of fsr2 to address data memory ? value of fsr2 post-decremented (not a physical register) n/a 42, 60 preinc2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) n/a 42, 60 plusw2 uses contents of fsr2 to address data memory ? value of fsr2 pre-incremented (not a physical register) ? value of fsr2 offset by w n/a 42, 60 fsr2h ? ? ? ? indirect data memory address pointer 2 high byte ---- 0000 42, 60 fsr2l indirect data memory address pointer 2 low byte xxxx xxxx 42, 60 legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: the sboren bit is only available when the boren1:boren0 configuration bits = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 2: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 3: the ra5 bit is only available when master clear reset is disabled (mclre configuration bit = 0 ); otherwise, ra5 reads as ? 0 ?. this bit is read-only. 4: ra6/ra7 and their associated latch and direction bits are i ndividually configured as port pins based on various primary oscillator modes. when disabled, these bits read as ? 0 ?. 5: bit 7 and bit 6 are cleared by user software or by a por. 6: reset condition of pwmen bits depends on the pwmpin configuration bit of config3l. 7: this bit has no effect if the configuration bit, wdten, is enabled.
pic18f1230/1330 ds39758b-page 56 advance information ? 2006 microchip technology inc. status ? ? ?novz dc c ---x xxxx 42, 58 tmr0h timer0 register high byte 0000 0000 42, 103 tmr0l timer0 register low byte xxxx xxxx 42, 103 t0con tmr0on t016bit t0cs t0se psa t0ps2 t0ps1 t0ps0 1111 1111 42, 101 osccon idlen ircf2 ircf1 ircf0 osts iofs scs1 scs0 0100 q000 42, 22 lvdcon ? ? irvst lvden lvdl3 lvdl2 lvdl1 lvdl0 --00 0101 42, 179 wdtcon ? ? ? ? ? ? ?swdten (7) ---- ---0 42, 195 rcon ipen sboren (1) ?ri to pd por bor 0q-1 11q0 42, 34 tmr1h timer1 register high byte xxxx xxxx 42, 109 tmr1l timer1 register low byte xxxx xxxx 42, 109 t1con rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 0000 0000 42, 105 adresh a/d result register high byte xxxx xxxx 42, 172 adresl a/d result register low byte xxxx xxxx 42, 172 adcon0 sevten ? ? ? chs1 chs0 go/done adon 0--- 0000 42, 163 adcon1 ? ? ? vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 ---0 1111 42, 164 adcon2 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 0-00 0000 42, 165 baudcon abdovf rcidl ? sckp brg16 ? wue abden 01-0 0-00 42, 144 cvrcon cvren ? cvrr cvrss cvr3 cvr2 cvr1 cvr0 0-00 0000 42, 177 cmcon c2out c1out c0out ? ? cmen2 cmen1 cmen0 000- -000 42, 173 spbrgh eusart baud rate generator register high byte 0000 0000 42, 146 spbrg eusart baud rate generator register low byte 0000 0000 42, 146 rcreg eusart receive register 0000 0000 42, 153 txreg eusart transmit register 0000 0000 42, 151 txsta csrc tx9 txen sync sendb brgh trmt tx9d 0000 0010 42, 142 rcsta spen rx9 sren cren adden ferr oerr rx9d 0000 000x 42, 143 eeadr eeprom address register 0000 0000 43, 75 eedata eeprom data register 0000 0000 43, 75 eecon2 eeprom control register 2 (not a physical register) 0000 0000 43, 66 eecon1 eepgd cfgs ? free wrerr wren wr rd xx-0 x000 42, 67 ipr3 ? ? ?ptip ? ? ? ? ---1 ---- 43, 97 pir3 ? ? ?ptif ? ? ? ? ---0 ---- 43, 93 pie3 ? ? ?ptie ? ? ? ? ---0 ---- 43, 95 ipr2 oscfip ? ? eeip ?lvdip ? ? 1--1 -1-- 43, 97 pir2 oscfif ? ?eeif ?lvdif ? ? 0--0 -0-- 43, 93 pie2 oscfie ? ? eeie ?lvdie ? ? 0--0 -0-- 43, 95 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip -111 1111 43, 96 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if -000 0000 43, 92 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie -000 0000 43, 94 osctune intsrc pllen (2) ? tun4 tun3 tun2 tun1 tun0 00-0 0000 43, 19 ptcon0 ptops3 ptops2 ptops1 ptops0 ptckps1 ptckps0 ptmod1 ptmod0 0000 0000 43, 116 ptcon1 pten ptdir ? ? ? ? ? ? 00-- ---- 43, 116 table 5-2: register file summary (pic18f1230/1330) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: the sboren bit is only available when the boren1:boren0 configuration bits = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 2: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 3: the ra5 bit is only available when master clear reset is disabled (mclre configuration bit = 0 ); otherwise, ra5 reads as ? 0 ?. this bit is read-only. 4: ra6/ra7 and their associated latch and direction bits are i ndividually configured as port pins based on various primary oscillator modes. when disabled, these bits read as ? 0 ?. 5: bit 7 and bit 6 are cleared by user software or by a por. 6: reset condition of pwmen bits depends on the pwmpin configuration bit of config3l. 7: this bit has no effect if the configuration bit, wdten, is enabled.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 57 ptmrl pwm time base register (lower 8 bits) 0000 0000 43, 119 ptmrh ? ? ? ? pwm time base register (upper 4 bits) ---- 0000 43, 119 ptperl pwm time base period register (lower 8 bits) 1111 1111 43, 119 ptperh ? ? ? ? pwm time base period register (upper 4 bits) ---- 1111 43, 119 trisb portb data direction control register 1111 1111 43, 84 trisa trisa7 (4) trisa6 (4) porta data direction control register 1111 1111 43, 81 pdc0l pwm duty cycle #0l register (lower 8 bits) 0000 0000 43, 125 pdc0h ? ? pwm duty cycle #0h register (upper 6 bits) --00 0000 43, 125 pdc1l pwm duty cycle #1l register (lower 8 bits) 0000 0000 43, 125 pdc1h ? ? pwm duty cycle #1h register (upper 6 bits) --00 0000 43, 125 pdc2l pwm duty cycle #2l register (lower 8 bits) 0000 0000 43, 125 pdc2h ? ? pwm duty cycle #2h register (upper 6 bits) --00 0000 43, 125 fltconfig brfen ? ? ? ? fltas fltamod fltaen 0--- -000 43, 137 latb portb data latch register (read and write to data latch) xxxx xxxx 43, 84 lata lata7 (4) lata6 (4) porta data latch register (read and write to data latch) xxxx xxxx 43, 81 sevtcmpl pwm special event compare register (lower 8 bits) 0000 0000 43, 138 sevtcmph ? ? ? ? pwm special event compare register (upper 4 bits) ---- 0000 44, 138 pwmcon0 ?pwmen2 (6) pwmen1 (6) pwmen0 (6) ? pmod2 pmod1 pmod0 -100 -000 44, 117 -000 -000 pwmcon1 sevops3 sevops2 sevops1 sevops0 sevtdir ? udis osync 0000 0-00 44, 118 dtcon dtps1 dtps0 dt5 dt4 dt3 dt2 dt1 dt0 0000 0000 44, 130 ovdcond ? ? povd5 povd4 povd3 povd2 povd1 povd0 --11 1111 44, 134 ovdcons ? ? pout5 pout4 pout3 pout2 pout1 pout0 --00 0000 44, 134 portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 xxxx xxxx 44, 84 porta ra7 (4) ra6 (4) ra5 (3) ra4 ra3 ra2 ra1 ra0 xx0x xxxx 44, 81 table 5-2: register file summary (pic18f1230/1330) (continued) file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 value on por, bor details on page: legend: x = unknown, u = unchanged, - = unimplemented, q = value depends on condition note 1: the sboren bit is only available when the boren1:boren0 configuration bits = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 2: the pllen bit is only available in specific oscillator configuration; otherwise, it is disabled and reads as ? 0 ?. see section 2.6.4 ?pll in intosc modes? . 3: the ra5 bit is only available when master clear reset is disabled (mclre configuration bit = 0 ); otherwise, ra5 reads as ? 0 ?. this bit is read-only. 4: ra6/ra7 and their associated latch and direction bits are i ndividually configured as port pins based on various primary oscillator modes. when disabled, these bits read as ? 0 ?. 5: bit 7 and bit 6 are cleared by user software or by a por. 6: reset condition of pwmen bits depends on the pwmpin configuration bit of config3l. 7: this bit has no effect if the configuration bit, wdten, is enabled.
pic18f1230/1330 ds39758b-page 58 advance information ? 2006 microchip technology inc. 5.3.5 status register the status register, shown in register 5-2, contains the arithmetic status of the alu. as with any other sfr, it can be the operand for any instruction. if the status register is the destination for an instruc- tion that affects the z, dc, c, ov or n bits, the results of the instruction are not written; instead, the status register is updated according to the instruction performed. therefore, the result of an instruction with the status register as its destination may be different than intended. as an example, clrf status will set the z bit and leave the remaining status bits unchanged (? 000u u1uu ?). it is recommended that only bcf , bsf , swapf , movff and movwf instructions are used to alter the status register because these instructions do not affect the z, c, dc, ov or n bits in the status register. for other instructions that do not affect status bits, see the instruction set summaries in table 21-2 and table 21-3. note: the c and dc bits operate as the borrow and digit borrow bits, respectively, in subtraction. register 5-2: status register u-0 u-0 u-0 r/w-x r/w-x r/w-x r/w-x r/w-x ? ? ?nov zdc (1) c (2) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 n: negative bit this bit is used for signed arithmetic (2?s complement). it indicates whether the result was negative (alu msb = 1 ). 1 = result was negative 0 = result was positive bit 3 ov: overflow bit this bit is used for signed arithmetic (2?s complement). it indicates an overflow of the 7-bit magnitude which causes the sign bit (bit 7 of the result) to change state. 1 = overflow occurred for signed arithmetic (in this arithmetic operation) 0 = no overflow occurred bit 2 z: zero bit 1 = the result of an arithmetic or logic operation is zero 0 = the result of an arithmetic or logic operation is not zero bit 1 dc: digit carry/borrow bit (1) for addwf , addlw , sublw and subwf instructions: 1 = a carry-out from the 4th low-order bit of the result occurred 0 = no carry-out from the 4th low-order bit of the result bit 0 c: carry/borrow bit (2) for addwf , addlw , sublw and subwf instructions: 1 = a carry-out from the most significant bit of the result occurred 0 = no carry-out from the most significant bit of the result occurred note 1: for borrow , the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either bit 4 or bit 3 of the source register. 2: for borrow , the polarity is reversed. a subtraction is executed by adding the 2?s complement of the second operand. for rotate ( rrf , rlf ) instructions, this bit is loaded with either the high or low-order bit of the source register.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 59 5.4 data addressing modes the data memory space can be addressed in several ways. for most instructions, the addressing mode is fixed. other instructions may use up to three modes, depending on which operands are used and whether or not the extended instruction set is enabled. the addressing modes are: ? inherent ? literal ?direct ?indirect an additional addressing mode, indexed literal offset, is available when the extended instruction set is enabled (xinst configuration bit = 1 ). its operation is discussed in greater detail in section 5.5.1 ?indexed addressing with literal offset? . 5.4.1 inherent and literal addressing many pic18 control instructions do not need any argument at all; they either perform an operation that globally affects the device or they operate implicitly on one register. this addressing mode is known as inherent addressing. examples include sleep , reset and daw . other instructions work in a similar way but require an additional explicit argument in the opcode. this is known as literal addressing mode because they require some literal value as an argument. examples include addlw and movlw , which respectively, add or move a literal value to the w register. other examples include call and goto , which include a 20-bit program memory address. 5.4.2 direct addressing direct addressing specifies all or part of the source and/or destination address of the operation within the opcode itself. the options are specified by the arguments accompanying the instruction. in the core pic18 instruction set, bit-oriented and byte- oriented instructions use some version of direct addressing by default. all of these instructions include some 8-bit literal address as their least significant byte. this address specifies either a register address in one of the banks of data ram ( section 5.3.3 ?general purpose register file? ) or a location in the access bank ( section 5.3.2 ?access bank? ) as the data source for the instruction. the access ram bit ?a? determines how the address is interpreted. when ?a? is ? 1 ?, the contents of the bsr ( section 5.3.1 ?bank select register (bsr)? ) are used with the address to determine the complete 12-bit address of the register. when ?a? is ? 0 ?, the address is interpreted as being a register in the access bank. addressing that uses the access ram is sometimes also known as direct forced addressing mode. a few instructions, such as movff , include the entire 12-bit address (either source or destination) in their opcodes. in these cases, the bsr is ignored entirely. the destination of the operation?s results is determined by the destination bit ?d?. when ?d? is ? 1 ?, the results are stored back in the source register, overwriting its original contents. when ?d? is ? 0 ?, the results are stored in the w register. instructions without the ?d? argument have a destination that is implicit in the instruction; their destination is either the target register being operated on or the w register. 5.4.3 indirect addressing indirect addressing allows the user to access a location in data memory without giving a fixed address in the instruction. this is done by using file select registers (fsrs) as pointers to the locations to be read or written to. since the fsrs are themselves located in ram as special function registers, they can also be directly manipulated under program control. this makes fsrs very useful in implementing data structures, such as tables and arrays in data memory. the registers for indirect addressing are also implemented with indirect file operands (indfs) that permit automatic manipulation of the pointer value with auto-incrementing, auto-decrementing or offsetting with another value. this allows for efficient code, using loops, such as the example of clearing an entire ram bank in example 5-5. example 5-5: how to clear ram (bank 0) using indirect addressing note: the execution of some instructions in the core pic18 instruction set are changed when the pic18 extended instruction set is enabled. see section 5.5 ?data memory and the extended instruction set? for more information. lfsr fsr0, 00h ; next clrf postinc0 ; clear indf ; register then ; inc pointer btfss fsr0h, 0 ; all done with ; bank0? bra next ; no, clear next continue ; yes, continue
pic18f1230/1330 ds39758b-page 60 advance information ? 2006 microchip technology inc. 5.4.3.1 fsr registers and the indf operand at the core of indirect addressing are three sets of registers: fsr0, fsr1 and fsr2. each represents a pair of 8-bit registers, fsrnh and fsrnl. the four upper bits of the fsrnh register are not used so each fsr pair holds a 12-bit value. this represents a value that can address the entire range of the data memory in a linear fashion. the fsr register pairs, then, serve as pointers to data memory locations. indirect addressing is accomplished with a set of indirect file operands, indf0 through indf2. these can be thought of as ?virtual? registers: they are mapped in the sfr space but are not physically implemented. reading or writing to a particular indf register actually accesses its corresponding fsr register pair. a read from indf1, for example, reads the data at the address indicated by fsr1h:fsr1l. instructions that use the indf registers as operands actually use the contents of their corresponding fsr as a pointer to the instruction?s target. the indf operand is just a convenient way of using the pointer. because indirect addressing uses a full 12-bit address, data ram banking is not necessary. thus, the current contents of the bsr and the access ram bit have no effect on determining the target address. 5.4.3.2 fsr registers and postinc, postdec, preinc and plusw in addition to the indf operand, each fsr register pair also has four additional indirect operands. like indf, these are ?virtual? registers that cannot be indirectly read or written to. accessing these registers actually accesses the associated fsr register pair, but also performs a specific action on its stored value. they are: ? postdec: accesses the fsr value, then automatically decrements it by 1 afterwards ? postinc: accesses the fsr value, then automatically increments it by 1 afterwards ? preinc: increments the fsr value by 1, then uses it in the operation ? plusw: adds the signed value of the w register (range of -127 to 128) to that of the fsr and uses the new value in the operation. in this context, accessing an indf register uses the value in the fsr registers without changing them. sim- ilarly, accessing a plusw register gives the fsr value offset by that in the w register; neither value is actually changed in the operation. accessing the other virtual registers changes the value of the fsr registers. operations on the fsrs with postdec, postinc and preinc affect the entire register pair; that is, roll- overs of the fsrnl register from ffh to 00h carry over to the fsrnh register. on the other hand, results of these operations do not change the value of any flags in the status register (e.g., z, n, ov, etc.). figure 5-7: indirect addressing fsr1h:fsr1l 0 7 data memory 000h 100h 200h 300h f00h e00h fffh bank 0 bank 1 bank 2 bank 14 bank 15 bank 3 through bank 13 addwf, indf1, 1 0 7 using an instruction with one of the indirect addressing registers as the operand.... ...uses the 12-bit address stored in the fsr pair associated with that register.... ...to determine the data memory location to be used in that operation. in this case, the fsr1 pair contains ecch. this means the contents of location ecch will be added to that of the w register and stored back in ecch. xxxx 1110 11001100
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 61 the plusw register can be used to implement a form of indexed addressing in the data memory space. by manipulating the value in the w register, users can reach addresses that are fixed offsets from pointer addresses. in some applications, this can be used to implement some powerful program control structure, such as software stacks, inside of data memory. 5.4.3.3 operations by fsrs on fsrs indirect addressing operations that target other fsrs or virtual registers represent special cases. for example, using an fsr to point to one of the virtual registers will not result in successful operations. as a specific case, assume that fsr0h:fsr0l contains fe7h, the address of indf1. attempts to read the value of the indf1 using indf0 as an operand will return 00h. attempts to write to indf1 using indf0 as the operand will result in a nop . on the other hand, using the virtual registers to write to an fsr pair may not occur as planned. in these cases, the value will be written to the fsr pair but without any incrementing or decrementing. thus, writing to indf2 or postdec2 will write the same value to the fsr2h:fsr2l. since the fsrs are physical registers mapped in the sfr space, they can be manipulated through all direct operations. users should proceed cautiously when working on these registers, particularly if their code uses indirect addressing. similarly, operations by indirect addressing are gener- ally permitted on all other sfrs. users should exercise the appropriate caution that they do not inadvertently change settings that might affect the operation of the device. 5.5 data memory and the extended instruction set enabling the pic18 extended instruction set (xinst configuration bit = 1 ) significantly changes certain aspects of data memory and its addressing. specifically, the use of the access bank for many of the core pic18 instructions is different; this is due to the introduction of a new addressing mode for the data memory space. what does not change is just as important. the size of the data memory space is unchanged, as well as its linear addressing. the sfr map remains the same. core pic18 instructions can still operate in both direct and indirect addressing mode; inherent and literal instructions do not change at all. indirect addressing with fsr0 and fsr1 also remains unchanged. 5.5.1 indexed addressing with literal offset enabling the pic18 extended instruction set changes the behavior of indirect addressing using the fsr2 register pair within access ram. under the proper conditions, instructions that use the access bank ? that is, most bit-oriented and byte-oriented instructions ? can invoke a form of indexed addressing using an offset specified in the instruction. this special addressing mode is known as indexed addressing with literal offset, or indexed literal offset mode. when using the extended instruction set, this addressing mode requires the following: ? the use of the access bank is forced (?a? = 0 ); and ? the file address argument is less than or equal to 5fh. under these conditions, the file address of the instruction is not interpreted as the lower byte of an address (used with the bsr in direct addressing), or as an 8-bit address in the access bank. instead, the value is interpreted as an offset value to an address pointer, specified by fsr2. the offset and the contents of fsr2 are added to obtain the target address of the operation. 5.5.2 instructions affected by indexed literal offset mode any of the core pic18 instructions that can use direct addressing are potentially affected by the indexed literal offset addressing mode. this includes all byte-oriented and bit-oriented instructions, or almost one-half of the standard pic18 instruction set. instructions that only use inherent or literal addressing modes are unaffected. additionally, byte-oriented and bit-oriented instructions are not affected if they do not use the access bank (access ram bit is ? 1 ?), or include a file address of 60h or above. instructions meeting these criteria will continue to execute as before. a comparison of the different possible addressing modes when the extended instruction set is enabled is shown in figure 5-8. those who desire to use bit-oriented or byte-oriented instructions in the indexed literal offset mode should note the changes to assembler syntax for this mode. this is described in more detail in section 21.2.1 ?extended instruction syntax? .
pic18f1230/1330 ds39758b-page 62 advance information ? 2006 microchip technology inc. figure 5-8: comparing addressing options for bit-oriented and byte-oriented instructions (extended instruction set enabled) example instruction: addwf, f, d, a (opcode: 0010 01da ffff ffff ) when ?a? = 0 and f 60h: the instruction executes in direct forced mode. ?f? is interpreted as a location in the access ram between 060h and 0ffh. this is the same as locations 060h to 07fh (bank 0) and f80h to fffh (bank 15) of data memory. locations below 60h are not available in this addressing mode. when ?a? = 0 and f 5fh: the instruction executes in indexed literal offset mode. ?f? is interpreted as an offset to the address value in fsr2. the two are added together to obtain the address of the target register for the instruction. the address can be anywhere in the data memory space. note that in this mode, the correct syntax is now: addwf [k], d where ?k? is the same as ?f?. when ?a? = 1 (all values of f): the instruction executes in direct mode (also known as direct long mode). ?f? is interpreted as a location in one of the 16 banks of the data memory space. the bank is designated by the bank select register (bsr). the address can be in any implemented bank in the data memory space. 000h 060h 100h f00h f80h fffh valid range 00h 60h 80h ffh data memory access ram bank 0 bank 1 through bank 14 bank 15 sfrs 000h 080h 100h f00h f80h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs fsr2h fsr2l ffffffff 001001da ffffffff 001001da 000h 080h 100h f00h f80h fffh data memory bank 0 bank 1 through bank 14 bank 15 sfrs for ?f? bsr 00000000 080h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 63 5.5.3 mapping the access bank in indexed literal offset addressing mode the use of indexed literal offset addressing mode effectively changes how the first 96 locations of access ram (00h to 5fh) are mapped. rather than containing just the contents of the bottom half of bank 0, this mode maps the contents from bank 0 and a user-defined ?window? that can be located anywhere in the data memory space. the value of fsr2 establishes the lower boundary of the addresses mapped into the window, while the upper boundary is defined by fsr2 plus 95 (5fh). addresses in the access ram above 5fh are mapped as previously described (see section 5.3.2 ?access bank? ). an example of access bank remapping in this addressing mode is shown in figure 5-9. remapping of the access bank applies only to operations using the indexed literal offset addressing mode. operations that use the bsr (access ram bit is ? 1 ?) will continue to use direct addressing as before. 5.6 pic18 instruction execution and the extended instruction set enabling the extended instruction set adds eight additional commands to the existing pic18 instruction set. these instructions are executed as described in section 21.2 ?extended instruction set? . figure 5-9: remapping the access bank with indexed literal offset addressing mode data memory 000h 100h f80h f00h fffh bank 0 bank 15 bank 1 through bank 14 sfrs 05fh addwf f, d, a fsr2h:fsr2l = 090h locations in the region from the fsr2 pointer (090h) to the pointer plus 05fh (0efh) are mapped to the bottom of the access ram (000h-05fh). locations in bank 0 from 060h to 07fh are mapped, as usual, to the middle of the access bank. special function registers at f80h through fffh are mapped to 80h through ffh, as usual. bank 0 addresses below 5fh can still be addressed by using the bsr. access bank 00h 80h ffh 7fh sfrs bank 0 ?window? bank 0 bank 0 window example situation: 07fh 090h 0efh 5fh
pic18f1230/1330 ds39758b-page 64 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 65 6.0 flash program memory the flash program memory is readable, writable and erasable during normal operation over the entire v dd range. a read from program memory is executed on one byte at a time. a write to program memory is executed on blocks of 8 bytes at a time. program memory is erased in blocks of 64 bytes at a time. a bulk erase operation may not be issued from user code. writing or erasing program memory will cease instruction fetches until the operation is complete. the program memory cannot be accessed during the write or erase, therefore, code cannot execute. an internal programming timer terminates program memory writes and erases. a value written to program memory does not need to be a valid instruction. executing a program memory location that forms an invalid instruction results in a nop . 6.1 table reads and table writes in order to read and write program memory, there are two operations that allow the processor to move bytes between the program memory space and the data ram: ? table read ( tblrd ) ? table write ( tblwt ) the program memory space is 16 bits wide, while the data ram space is 8 bits wide. table reads and table writes move data between these two memory spaces through an 8-bit register (tablat). table read operations retrieve data from program memory and place it into the data ram space. figure 6-1 shows the operation of a table read with program memory and data ram. table write operations store data from the data memory space into holding registers in program memory. the procedure to write the contents of the holding registers into program memory is detailed in section 6.5 ?writing to flash program memory? . figure 6-2 shows the operation of a table write with program memory and data ram. table operations work with byte entities. a table block containing data, rather than program instructions, is not required to be word-aligned. therefore, a table block can start and end at any byte address. if a table write is being used to write executable code into program memory, program instructions will need to be word-aligned. figure 6-1: table read operation table pointer (1) table latch (8-bit) program memory tblptrh tblptrl tablat tblptru instruction: tblrd * note 1: table pointer register points to a byte in program memory. program memory (tblptr)
pic18f1230/1330 ds39758b-page 66 advance information ? 2006 microchip technology inc. figure 6-2: table write operation 6.2 control registers several control registers are used in conjunction with the tblrd and tblwt instructions. these include the: ? eecon1 register ? eecon2 register ? tablat register ? tblptr registers 6.2.1 eecon1 and eecon2 registers the eecon1 register (register 6-1) is the control register for memory accesses. the eecon2 register is not a physical register; it is used exclusively in the memory write and erase sequences. reading eecon2 will read all ? 0 ?s. the eepgd control bit determines if the access will be a program or data eeprom memory access. when clear, any subsequent operations will operate on the data eeprom memory. when set, any subsequent operations will operate on the program memory. the cfgs control bit determines if the access will be to the configuration/calibration registers or to program memory/data eeprom memory. when set, subsequent operations will operate on configuration registers regardless of eepgd (see section 19.0 ?special features of the cpu? ). when clear, memory selection access is determined by eepgd. the free bit, when set, will allow a program memory erase operation. when free is set, the erase operation is initiated on the next wr command. when free is clear, only writes are enabled. the wren bit, when set, will allow a write operation. on power-up, the wren bit is clear. the wrerr bit is set in hardware when the wr bit is set and cleared when the internal programming timer expires and the write operation is complete. the wr control bit initiates write operations. the bit cannot be cleared, only set, in software; it is cleared in hardware at the completion of the write operation. table pointer (1) table latch (8-bit) tblptrh tblptrl tablat program memory (tblptr) tblptru instruction: tblwt * note 1: table pointer actually points to one of 8 holding registers, the address of which is determined by tblptrl<5:0>. the process for physically writing dat a to the program memory array is discussed in section 6.5 ?writing to flash program memory? . holding registers program memory note: during normal operation, the wrerr may read as ? 1 ?. this can indicate that a write operation was prematurely termi- nated by a reset, or a write operation was attempted improperly. note: the eeif interrupt flag bit (pir2<4>) is set when the write is complete. it must be cleared in software.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 67 register 6-1: eecon1: eeprom control register 1 r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr (1) wren wr rd bit 7 bit 0 legend: s = settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data eeprom or configuration select bit 1 = access configuration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write-only bit 3 wrerr: flash program/data eeprom error flag bit (1) 1 = a write operation is prematurely terminated (any reset during self-timed programming in normal operation, or an improper write attempt) 0 = the write operation completed bit 2 wren: flash program/data eeprom write enable bit 1 = allows write cycles to flash program/data eeprom 0 = inhibits write cycles to flash program/data eeprom bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle or a program memory erase cycle or write cycle. (the operation is self-timed and the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to the eeprom is complete bit 0 rd: read control bit 1 = initiates an eeprom read. (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 or cfgs = 1 .) 0 = does not initiate an eeprom read note 1: when a wrerr occurs, the eepgd and cfgs bits are not cleared. this allows tracing of the error condition.
pic18f1230/1330 ds39758b-page 68 advance information ? 2006 microchip technology inc. 6.2.2 tablat ? table latch register the table latch (tablat) is an 8-bit register mapped into the sfr space. the table latch register is used to hold 8-bit data during data transfers between program memory and data ram. 6.2.3 tblptr ? table pointer register the table pointer (tblptr) register addresses a byte within the program memory. the tblptr is comprised of three sfr registers: table pointer upper byte, table pointer high byte and table pointer low byte (tblptru:tblptrh:tblptrl). these three registers join to form a 22-bit wide pointer. the low- order 21 bits allow the device to address up to 2 mbytes of program memory space. the 22nd bit allows access to the device id, the user id and the configuration bits. the table pointer register, tblptr, is used by the tblrd and tblwt instructions. these instructions can update the tblptr in one of four ways based on the table operation. these operations are shown in table 6-1. these operations on the tblptr only affect the low-order 21 bits. 6.2.4 table pointer boundaries tblptr is used in reads, writes and erases of the flash program memory. when a tblrd is executed, all 22 bits of the tblptr determine which byte is read from program memory into tablat. when a tblwt is executed, the three lsbs of the table pointer register (tblptr<2:0>) determine which of the 8 program memory holding registers is written to. when the timed write to program memory begins (via the wr bit), the 19 msbs of the tblptr (tblptr<21:3>) determine which program memory block of 8 bytes is written to. for more detail, see section 6.5 ?writing to flash program memory? . when an erase of program memory is executed, the 16 msbs of the table pointer register (tblptr<21:6>) point to the 64-byte block that will be erased. the least significant bits (tblptr<5:0>) are ignored. figure 6-3 describes the relevant boundaries of tblptr based on flash program memory operations. table 6-1: table pointer operations with tblrd and tblwt instructions figure 6-3: table pointer boundaries based on operation example operation on table pointer tblrd* tblwt* tblptr is not modified tblrd*+ tblwt*+ tblptr is incremented after the read/write tblrd*- tblwt*- tblptr is decremented after the read/write tblrd+* tblwt+* tblptr is incremented before the read/write 21 16 15 87 0 table erase/write table write table read ? tblptr<21:0> tblptrl tblptrh tblptru tblptr<5:0> tblptr<21:6>
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 69 6.3 reading the flash program memory the tblrd instruction is used to retrieve data from program memory and places it into data ram. table reads from program memory are performed one byte at a time. tblptr points to a byte address in program space. executing tblrd places the byte pointed to into tablat. in addition, tblptr can be modified automatically for the next table read operation. the internal program memory is typically organized by words. the least significant bit of the address selects between the high and low bytes of the word. figure 6-4 shows the interface between the internal program memory and the tablat. figure 6-4: reads from flash program memory example 6-1: reading a flash program memory word (even byte address) program memory (odd byte address) tblrd tablat tblptr = xxxxx1 fetch instruction register (ir) read register tblptr = xxxxx0 movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the word movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_word tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_even tblrd*+ ; read into tablat and increment movf tablat, w ; get data movwf word_odd
pic18f1230/1330 ds39758b-page 70 advance information ? 2006 microchip technology inc. 6.4 erasing flash program memory the minimum erase block is 32 words or 64 bytes. only through the use of an external programmer, or through icsp control, can larger blocks of program memory be bulk erased. word erase in the flash array is not supported. when initiating an erase sequence from the micro- controller itself, a block of 64 bytes of program memory is erased. the most significant 16 bits of the tblptr<21:6> point to the block being erased. tblptr<5:0> are ignored. the eecon1 register commands the erase operation. the eepgd bit must be set to point to the flash program memory. the wren bit must be set to enable write operations. the free bit is set to select an erase operation. for protection, the write initiate sequence for eecon2 must be used. a long write is necessary for erasing the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. 6.4.1 flash program memory erase sequence the sequence of events for erasing a block of internal program memory location is: 1. load table pointer register with address of row being erased. 2. set the eecon1 register for the erase operation: ? set eepgd bit to point to program memory; ? clear the cfgs bit to access program memory; ? set wren bit to enable writes; ? set free bit to enable the erase. 3. disable interrupts. 4. write 55h to eecon2. 5. write 0aah to eecon2. 6. set the wr bit. this will begin the row erase cycle. 7. the cpu will stall for duration of the erase (about 2 ms using internal timer). 8. re-enable interrupts. example 6-2: erasing a flash program memory row movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl erase_row bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts required movlw 55h sequence movwf eecon2 ; write 55h movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 71 6.5 writing to flash program memory the minimum programming block is 4 words or 8 bytes. word or byte programming is not supported. table writes are used internally to load the holding registers needed to program the flash memory. there are 8 holding registers used by the table writes for programming. since the table latch (tablat) is only a single byte, the tblwt instruction may need to be executed 8 times for each programming operation. all of the table write operations will essentially be short writes because only the holding registers are written. at the end of updating the 8 holding registers, the eecon1 register must be written to in order to start the programming operation with a long write. the long write is necessary for programming the internal flash. instruction execution is halted while in a long write cycle. the long write will be terminated by the internal programming timer. the eeprom on-chip timer controls the write time. the write/erase voltages are generated by an on-chip charge pump, rated to operate over the voltage range of the device. figure 6-5: table writes to flash program memory 6.5.1 flash program memory write sequence the sequence of events for programming an internal program memory location should be: 1. read 8 bytes into ram. 2. update data values in ram as necessary. 3. load table pointer register with address being erased. 4. execute the row erase procedure. 5. load table pointer register with address of first byte being written. 6. write the 8 bytes into the holding registers with auto-increment. 7. set the eecon1 register for the write operation: ? set eepgd bit to point to program memory; ? clear the cfgs bit to access program memory; ? set wren to enable byte writes. 8. disable interrupts. 9. write 55h to eecon2. 10. write 0aah to eecon2. 11. set the wr bit. this will begin the write cycle. 12. the cpu will stall for duration of the write (about 2 ms using internal timer). 13. re-enable interrupts. 14. verify the memory (table read). this procedure will require about 6 ms to update one row of 8 bytes of memory. an example of the required code is given in example 6-3. note: the default value of the holding registers on device resets and after write operations is ffh. a write of ffh to a holding register does not modify that byte. this means that individual bytes of program memory may be modified, provided that the change does not attempt to change any bit from a ? 0 ? to a ? 1 ?. when modifying individual bytes, it is not necessary to load all 8 holding registers before executing a write operation. tablat tblptr = xxxxx7 tblptr = xxxxx1 tblptr = xxxxx0 write register tblptr = xxxxx2 program memory holding register holding register holding register holding register 8 8 8 8 note: before setting the wr bit, the table pointer address needs to be within the intended address range of the 8 bytes in the holding register.
pic18f1230/1330 ds39758b-page 72 advance information ? 2006 microchip technology inc. example 6-3: writing to flash program memory movlw d'8 ; number of bytes in erase block movwf counter movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl read_block tblrd*+ ; read into tablat, and inc movf tablat, w ; get data movwf postinc0 ; store data decfsz counter ; done? bra read_block ; repeat modify_word movlw data_addr_high ; point to buffer movwf fsr0h movlw data_addr_low movwf fsr0l movlw new_data_low ; update buffer word movwf postinc0 movlw new_data_high movwf indf0 erase_block movlw code_addr_upper ; load tblptr with the base movwf tblptru ; address of the memory block movlw code_addr_high movwf tblptrh movlw code_addr_low movwf tblptrl bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bsf eecon1, free ; enable row erase operation bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start erase (cpu stall) bsf intcon, gie ; re-enable interrupts tblrd*- ; dummy read decrement movlw buffer_addr_high ; point to buffer movwf fsr0h movlw buffer_addr_low movwf fsr0l write_buffer_back movlw d?8 ; number of bytes in holding register movwf counter write_byte_to_hregs movff postinc0, wreg ; get low byte of buffer data movwf tablat ; present data to table latch tblwt+* ; write data, perform a short write ; to internal tblwt holding register. decfsz counter ; loop until buffers are full bra write_word_to_hregs
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 73 example 6-3: writing to flash program memory (continued) 6.5.2 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 6.5.3 unexpected termination of write operation if a write is terminated by an unplanned event, such as loss of power or an unexpected reset, the memory location just programmed should be verified and reprogrammed, if needed. if the write operation is interrupted by a mclr reset or a wdt time-out reset during normal operation, the user can check the wrerr bit and rewrite the location(s) as needed. 6.5.4 protection against spurious writes to protect against spurious writes to flash program memory, the write initiate sequence must also be followed. see section 19.0 ?special features of the cpu? for more detail. 6.6 flash program operation during code protection see section 19.5 ?program verification and code protection? for details on code protection of flash program memory. table 6-2: registers associated with program flash memory program_memory bsf eecon1, eepgd ; point to flash program memory bcf eecon1, cfgs ; access flash program memory bsf eecon1, wren ; enable write to memory bcf intcon, gie ; disable interrupts movlw 55h required movwf eecon2 ; write 55h sequence movlw 0aah movwf eecon2 ; write 0aah bsf eecon1, wr ; start program (cpu stall) bsf intcon, gie ; re-enable interrupts bcf eecon1, wren ; disable write to memory name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page tblptru ? ? bit 21 program memory table pointer upper byte (tblptr<20:16>) 41 tbpltrh program memory table pointer high byte (tblptr<15:8>) 41 tblptrl program memory table pointer low byte (tblptr<7:0>) 41 tablat program memory table latch 41 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 eecon2 eeprom control register 2 (not a physical register) 43 eecon1 eepgd cfgs ? free wrerr wren wr rd 43 ipr2 oscfip ? ? eeip ? lvdip ? ?43 pir2 oscfif ? ? eeif ? lvdif ? ?43 pie2 oscfie ? ? eeie ? lvdie ? ?43 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/eeprom access.
pic18f1230/1330 ds39758b-page 74 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 75 7.0 data eeprom memory the data eeprom is readable and writable during normal operation over the entire v dd range. the data memory is not directly mapped in the register file space. instead, it is indirectly addressed through the special function registers (sfr). there are four sfrs used to read and write the program and data eeprom memory. these registers are: ? eecon1 ? eecon2 ? eedata ? eeadr the eeprom data memory allows byte read and write. when interfacing to the data memory block, eedata holds the 8-bit data for read/write and eeadr holds the address of the eeprom location being accessed. these devices have 128 bytes of data eeprom with an address range from 00h to ffh. the eeprom data memory is rated for high erase/ write cycle endurance. a byte write automatically erases the location and writes the new data (erase- before-write). the write time is controlled by an on-chip timer. the write time will vary with voltage and temperature, as well as from chip-to-chip. please refer to parameter d122 (table 22-1 in section 22.0 ?electrical characteristics? ) for exact limits. 7.1 eeadr register the eeprom address register can address 256 bytes of data eeprom. 7.2 eecon1 and eecon2 registers eecon1 is the control register for memory accesses. eecon2 is not a physical register. reading eecon2 will read all ? 0 ?s. the eecon2 register is used exclusively in the memory write and erase sequences. control bit, eepgd, determines if the access will be to program or data eeprom memory. when clear, operations will access the data eeprom memory. when set, program memory is accessed. control bit, cfgs, determines if the access will be to the configuration registers or to program memory/data eeprom memory. when set, subsequent operations access configuration registers. when cfgs is clear, the eepgd bit selects either program flash or data eeprom memory. the wren bit enables and disables erase and write operations. when set, erase and write operations are allowed. when clear, erase and write operations are disabled; the wr bit cannot be set while the wren bit is clear. this mechanism helps to prevent accidental writes to memory due to errant (unexpected) code execution. firmware should keep the wren bit clear at all times, except when starting erase or write operations. once firmware has set the wr bit, the wren bit may be cleared. clearing the wren bit will not affect the operation in progress. the wrerr bit is set when a write operation is interrupted by a reset. in these situations, the user can check the wrerr bit and rewrite the location. it is necessary to reload the data and address registers (eedata and eeadr), as these registers have cleared as a result of the reset. control bits, rd and wr, start read and erase/write operations, respectively. these bits are set by firmware and cleared by hardware at the completion of the operation. the rd bit cannot be set when accessing program memory (eepgd = 1 ). program memory is read using table read instructions. see section 6.1 ?table reads and table writes? regarding table reads. note: interrupt flag bit, eeif in the pir2 register, is set when write is complete. it must be cleared in software.
pic18f1230/1330 ds39758b-page 76 advance information ? 2006 microchip technology inc. register 7-1: eecon1: eeprom control register 1 r/w-x r/w-x u-0 r/w-0 r/w-x r/w-0 r/s-0 r/s-0 eepgd cfgs ? free wrerr (1) wren wr rd bit 7 bit 0 legend: s = settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 eepgd: flash program or data eeprom memory select bit 1 = access flash program memory 0 = access data eeprom memory bit 6 cfgs: flash program/data eeprom or configuration select bit 1 = access configuration registers 0 = access flash program or data eeprom memory bit 5 unimplemented: read as ? 0 ? bit 4 free: flash row erase enable bit 1 = erase the program memory row addressed by tblptr on the next wr command (cleared by completion of erase operation) 0 = perform write-only bit 3 wrerr: eeprom error flag bit (1) 1 = a write operation is prematurely terminated (mclr or wdt reset during self-timed erase or program operation) 0 = the write operation completed bit 2 wren: erase/write enable bit 1 = allows erase/write cycles 0 = inhibits erase/write cycles bit 1 wr: write control bit 1 = initiates a data eeprom erase/write cycle or a program memory erase cycle or write cycle. (the operation is self-timed and the bit is cleared by hardware once write is complete. the wr bit can only be set (not cleared) in software.) 0 = write cycle to is completed bit 0 rd: read control bit 1 = initiates a memory read. (read takes one cycle. rd is cleared in hardware. the rd bit can only be set (not cleared) in software. rd bit cannot be set when eepgd = 1 .) 0 = read completed note 1: when a wrerr occurs, the eepgd or free bit is not cleared. this allows tracing of the error condition.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 77 7.3 reading the data eeprom memory to read a data memory location, the user must write the address to the eeadr register, clear the eepgd control bit (eecon1<7>) and then set control bit rd (eecon1<0>). the data is available for the very next instruction cycle; therefore, the eedata register can be read by the next instruction. eedata will hold this value until another read operation, or until it is written to by the user (during a write operation). 7.4 writing to the data eeprom memory to write an eeprom data location, the address must first be written to the eeadr register and the data written to the eedata register. the sequence in example 7-2 must be followed to initiate the write cycle. the write will not begin if this sequence is not exactly followed (write 55h to eecon2, write 0aah to eecon2, then set wr bit) for each byte. it is strongly recommended that interrupts be disabled during this code segment. additionally, the wren bit in eecon1 must be set to enable writes. this mechanism prevents accidental writes to data eeprom due to unexpected code execution (i.e., runaway programs). the wren bit should be kept clear at all times, except when updating the eeprom. the wren bit is not cleared by hardware. after a write sequence has been initiated, eecon1, eeadr and eedata cannot be modified. the wr bit will be inhibited from being set unless the wren bit is set. the wren bit must be set on a previous instruc- tion. both wr and wren cannot be set with the same instruction. at the completion of the write cycle, the wr bit is cleared in hardware and the eeprom interrupt flag bit (eeif) is set. the user may either enable this interrupt or poll this bit. eeif must be cleared by software. 7.5 write verify depending on the application, good programming practice may dictate that the value written to the memory should be verified against the original value. this should be used in applications where excessive writes can stress bits near the specification limit. 7.6 protection against spurious write there are conditions when the device may not want to write to the data eeprom memory. to protect against spurious eeprom writes, various mechanisms have been built-in. on power-up, the wren bit is cleared. also, the power-up timer (72 ms duration) prevents eeprom write. the write initiate sequence and the wren bit together help prevent an accidental write during brown-out, power glitch, or software malfunction. example 7-1: data eeprom read example 7-2: data eeprom write movlw data_ee_addr ; movwf eeadr ; data memory address to read bcf eecon1, eepgd ; point to data memory bsf eecon1, rd ; eeprom read movf eedata, w ; w = eedata movlw data_ee_addr ; movwf eeadr ; data memory address to write movlw data_ee_data ; movwf eedata ; data memory value to write bcf eecon1, eepgd ; point to data memory bsf eecon1, wren ; enable writes bcf intcon, gie ; disable interrupts movlw 55h ; required movwf eecon2 ; write 55h sequence movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write bsf intcon, gie ; enable interrupts sleep ; wait for interrupt to signal write complete bcf eecon1, wren ; disable writes
pic18f1230/1330 ds39758b-page 78 advance information ? 2006 microchip technology inc. 7.7 operation during code-protect data eeprom memory has its own code-protect bits in configuration words. external read and write operations are disabled if either of these mechanisms are enabled. the microcontroller itself can both read and write to the internal data eeprom, regardless of the state of the code-protect configuration bit. refer to section 19.0 ?special features of the cpu? for additional information. 7.8 using the data eeprom the data eeprom is a high-endurance, byte addressable array that has been optimized for the storage of frequently changing information (e.g., program variables or other data that are updated often). frequently changing values will typically be updated more often than specification d124 or d124a. if this is not the case, an array refresh must be performed. for this reason, variables that change infrequently (such as constants, ids, calibration, etc.) should be stored in flash program memory. a simple data eeprom refresh routine is shown in example 7-3. example 7-3: data eeprom refresh routine table 7-1: registers associated with data eeprom memory note: if data eeprom is only used to store constants and/or data that changes rarely, an array refresh is likely not required. see specification d124 or d124a. clrf eeadr ; start at address 0 bcf eecon1, cfgs ; set for memory bcf eecon1, eepgd ; set for data eeprom bcf intcon, gie ; disable interrupts bsf eecon1, wren ; enable writes loop ; loop to refresh array bsf eecon1, rd ; read current address movlw 55h ; movwf eecon2 ; write 55h movlw 0aah ; movwf eecon2 ; write 0aah bsf eecon1, wr ; set wr bit to begin write btfsc eecon1, wr ; wait for write to complete bra $-2 incfsz eeadr, f ; increment address bra loop ; not zero, do it again bcf eecon1, wren ; disable writes bsf intcon, gie ; enable interrupts name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 eeadr eeprom address register 43 eedata eeprom data register 43 eecon2 eeprom control register 2 (not a physical register) 43 eecon1 eepgd cfgs ? free wrerr wren wr rd 43 ipr2 oscfip ? ? eeip ? lvdip ? ?43 pir2 oscfif ? ? eeif ? lvdif ? ?43 pie2 oscfie ? ? eeie ? lvdie ? ?43 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used during flash/ eeprom access.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 79 8.0 8 x 8 hardware multiplier 8.1 introduction all pic18 devices include an 8 x 8 hardware multiplier as part of the alu. the multiplier performs an unsigned operation and yields a 16-bit result that is stored in the product register pair, prodh:prodl. the multiplier?s operation does not affect any flags in the status register. making multiplication a hardware operation allows it to be completed in a single instruction cycle. this has the advantages of higher computational throughput and reduced code size for multiplication algorithms and allows the pic18 devices to be used in many applications previously reserved for digital signal processors. a comparison of various hardware and software multiply operations, along with the savings in memory and execution time, is shown in table 8-1. 8.2 operation example 8-1 shows the instruction sequence for an 8 x 8 unsigned multiplication. only one instruction is required when one of the arguments is already loaded in the wreg register. example 8-2 shows the sequence to do an 8 x 8 signed multiplication. to account for the sign bits of the arguments, each argument?s most significant bit (msb) is tested and the appropriate subtractions are done. example 8-1: 8 x 8 unsigned multiply routine example 8-2: 8 x 8 signed multiply routine table 8-1: performance comparison for various multiply operations movf arg1, w ; mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl movf arg1, w mulwf arg2 ; arg1 * arg2 -> ; prodh:prodl btfsc arg2, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg1 movf arg2, w btfsc arg1, sb ; test sign bit subwf prodh, f ; prodh = prodh ; - arg2 routine multiply method program memory (words) cycles (max) time @ 40 mhz @ 10 mhz @ 4 mhz 8 x 8 unsigned without hardware multiply 13 69 6.9 s27.6 s69 s hardware multiply 1 1 100 ns 400 ns 1 s 8 x 8 signed without hardware multiply 33 91 9.1 s36.4 s91 s hardware multiply 6 6 600 ns 2.4 s6 s 16 x 16 unsigned without hardware multiply 21 242 24.2 s96.8 s 242 s hardware multiply 28 28 2.8 s 11.2 s28 s 16 x 16 signed without hardware multiply 52 254 25.4 s 102.6 s 254 s hardware multiply 35 40 4.0 s16.0 s40 s
pic18f1230/1330 ds39758b-page 80 advance information ? 2006 microchip technology inc. example 8-3 shows the sequence to do a 16 x 16 unsigned multiplication. equation 8-1 shows the algorithm that is used. the 32-bit result is stored in four registers (res3:res0). equation 8-1: 16 x 16 unsigned multiplication algorithm example 8-3: 16 x 16 unsigned multiply routine example 8-4 shows the sequence to do a 16 x 16 signed multiply. equation 8-2 shows the algorithm used. the 32-bit result is stored in four registers (res3:res0). to account for the sign bits of the arguments, the msb for each argument pair is tested and the appropriate subtractions are done. equation 8-2: 16 x 16 signed multiplication algorithm example 8-4: 16 x 16 signed multiply routine res3:res0= arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) movf arg1l, w mulwf arg2l ; arg1l * arg2l-> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h-> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l-> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; res3:res0= arg1h:arg1l ? arg2h:arg2l = (arg1h ? arg2h ? 2 16 ) + (arg1h ? arg2l ? 2 8 ) + (arg1l ? arg2h ? 2 8 ) + (arg1l ? arg2l) + (-1 ? arg2h<7> ? arg1h:arg1l ? 2 16 ) + (-1 ? arg1h<7> ? arg2h:arg2l ? 2 16 ) movf arg1l, w mulwf arg2l ; arg1l * arg2l -> ; prodh:prodl movff prodh, res1 ; movff prodl, res0 ; ; movf arg1h, w mulwf arg2h ; arg1h * arg2h -> ; prodh:prodl movff prodh, res3 ; movff prodl, res2 ; ; movf arg1l, w mulwf arg2h ; arg1l * arg2h -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; movf arg1h, w ; mulwf arg2l ; arg1h * arg2l -> ; prodh:prodl movf prodl, w ; addwf res1, f ; add cross movf prodh, w ; products addwfc res2, f ; clrf wreg ; addwfc res3, f ; ; btfss arg2h, 7 ; arg2h:arg2l neg? bra sign_arg1 ; no, check arg1 movf arg1l, w ; subwf res2 ; movf arg1h, w ; subwfb res3 ; sign_arg1 btfss arg1h, 7 ; arg1h:arg1l neg? bra cont_code ; no, done movf arg2l, w ; subwf res2 ; movf arg2h, w ; subwfb res3 ; cont_code :
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 81 9.0 i/o ports depending on the device selected and features enabled, there are up to five ports available. some pins of the i/o ports are multiplexed with an alternate function from the peripheral features on the device. in general, when a peripheral is enabled, that pin may not be used as a general purpose i/o pin. each port has three registers for its operation. these registers are: ? tris register (data direction register) ? port register (reads the levels on the pins of the device) ? lat register (output latch) the data latch (lat register) is useful for read-modify- write operations on the value that the i/o pins are driving. a simplified model of a generic i/o port, without the interfaces to other peripherals, is shown in figure 9-1. figure 9-1: generic i/o port operation 9.1 porta, trisa and lata registers porta is an 8-bit wide, bidirectional port. the corresponding data direction register is trisa. setting a trisa bit (= 1 ) will make the corresponding porta pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisa bit (= 0 ) will make the corresponding porta pin an output (i.e., put the contents of the output latch on the selected pin). reading the porta register reads the status of the pins, whereas writing to it, will write to the port latch. the data latch (lata) register is also memory mapped. read-modify-write operations on the lata register read and write the latched output value for porta. pins ra6 and ra7 are multiplexed with the main oscillator pins; they are enabled as oscillator or i/o pins by the selection of the main oscillator in the configura- tion register (see section 19.1 ?configuration bits? for details). when they are not used as port pins, ra6 and ra7 and their associated tris and lat bits are read as ? 0 ?. the ra0 pin is multiplexed with one of the analog inputs, one of the external interrupt inputs, one of the interrupt-on-change inputs and one of the analog comparator inputs to become ra0/an0/int0/kbi0/ cmp0 pin. the ra1 pin is multiplexed with one of the analog inputs, one of the external interrupt inputs and one of the interrupt-on-change inputs to become ra1/an1/ int1/kbi1 pin. pins ra2 and ra3 are multiplexed with the enhanced usart transmission and reception input (see section 19.1 ?configuration bits? for details). the ra4 pin is multiplexed with the timer0 module clock input, one of the analog inputs and the analog v ref + input to become the ra4/t0cki/an2/v ref + pin. the fault detect input for pwm flta is multiplexed with pins ra5 and ra7. its placement is decided by clearing or setting the fltamx bit of configuration register 3h. the trisa register controls the direction of the porta pins, even when they are being used as analog inputs. the user must ensure the bits in the trisa register are maintained set when using them as analog inputs. example 9-1: initializing porta data bus wr lat wr tris rd port data latch tris latch rd tris input buffer i/o pin (1) q d ck q d ck en qd en rd lat or port note 1: i/o pins have diode protection to v dd and v ss . note: on a power-on reset, ra0, ra1, ra4 and ra5 are configured as analog inputs and read as ? 0 ?. ra2 and ra3 are configured as digital inputs. clrf porta ; initialize porta by ; clearing output ; data latches clrf lata ; alternate method ; to clear output ; data latches movlw 07h ; configure a/d movwf adcon1 ; for digital inputs movwf 07h ; configure comparators movwf cmcon ; for digital input movlw 0cfh ; value used to ; initialize data ; direction movwf trisa ; set ra<7:6,3:0> as inputs ; ra<5:4> as outputs
pic18f1230/1330 ds39758b-page 82 advance information ? 2006 microchip technology inc. table 9-1: porta i/o summary pin function tris setting i/o i/o type description ra0/an0/int0/ kbi0/cmp0 ra0 0 o dig lata<0> data output; not affected by analog input. 1 i ttl porta<0> data input; disabled when analog input enabled. an0 1 i ana analog input 0. int0 1 i st external interrupt 0. kbi0 1 i ttl interrupt-on-change pin. cmp0 1 i ana comparator 0 input. ra1/an1/int1/ kbi1 ra1 0 o dig lata<1> data output; not affected by analog input. 1 i ttl porta<1> data input; disabled when analog input enabled. an1 1 i ana analog input 1. int1 1 i st external interrupt 1. kbi1 1 i ttl interrupt-on-change pin. ra2/tx/ck ra2 0 o dig lata<2> data output; not affected by analog input. disabled when cv ref output enabled. 1 i ttl porta<2> data input. disabled when analog functions enabled; disabled when cv ref output enabled. tx 0 0 dig eusart asynchronous transmit. ck 0 o dig eusart synchronous clock. 1 ist ra3/rx/dt ra3 0 o dig lata<3> data output; not affected by analog input. 1 i ttl porta<3> data input; disabled when analog input enabled. rx 1 i ana eusart asynchronous receive. dt 0 o dig eusart synchronous data. 1 ittl ra4/t0cki/an2/ v ref + ra4 0 o dig lata<4> data output. 1 i st porta<4> data input; default configuration on por. t0cki 1 i st timer0 external clock input. an2 1 i ana analog input 2. v ref + 1 i ana a/d reference voltage (high) input. mclr /v pp /ra5/ flta mclr 1 i st master clear (reset) input. this pin is an active-low reset to the device. v pp 1 i ana programming voltage input. ra5 1 i st digital input. flta (1) 1 i st fault detect input for pwm. ra6/osc2/clko/ t1oso/t1cki/an3 ra6 0 o dig lata<6> data output. enabled in rcio, intio2 and ecio modes only. 1 i st porta<6> data input. enabled in rcio, intio2 and ecio modes only. osc2 0 o ana oscillator crystal output or external clock source output. clko 0 o ana oscillator crystal output. t1oso (2) 0 o ana timer1 oscillator output. t1cki (2) 1 i st timer1 clock input. an3 1 i ana analog input 3. ra7/osc1/clki/ t1osi/flta ra7 0 o dig lata<7> data output. disabled in external oscillator modes. 1 i ttl porta<7> data input. disabled in external oscillator modes. osc1 1 i ana oscillator crystal input or external clock source input. clki 1 i ana external clock source input. t1osi (2) 1 i ana timer1 oscillator input. flta (1) 1 i st fault detect input for pwm. legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; x = don?t care (tris bit does not affect port direction or is overridden for this option). note 1: placement of flta depends on the value of configuration bit, fltamx, of config3h. 2: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 83 table 9-2: summary of registers associated with porta name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page porta ra7 (1) ra6 (1) ra5 ra4 ra3 ra2 ra1 ra0 44 lata lata7 (1) lata6 (1) porta data latch register (read and write to data latch) 43 trisa trisa7 (1) trisa6 (1) porta data direction control register 43 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 41 adcon1 ? ? ? vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 42 cmcon c2out c1out c0out ? ? cmen2 cmen1 cmen0 42 cvrcon cvren ? cvrr cvrss cvr3 cvr2 cvr1 cvr0 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by porta. note 1: ra7:ra6 and their associated latch and data direction bits are enabled as i/o pins based on oscillator configuration; otherwise, they are read as ? 0 ?.
pic18f1230/1330 ds39758b-page 84 advance information ? 2006 microchip technology inc. 9.2 portb, trisb and latb registers portb is an 8-bit wide, bidirectional port. the corresponding data direction register is trisb. setting a trisb bit (= 1 ) will make the corresponding portb pin an input (i.e., put the corresponding output driver in a high-impedance mode). clearing a trisb bit (= 0 ) will make the corresponding portb pin an output (i.e., put the contents of the output latch on the selected pin). the data latch register (latb) is also memory mapped. read-modify-write operations on the latb register read and write the latched output value for portb. example 9-2: initializing portb each of the portb pins has a weak internal pull-up. a single control bit can turn on all the pull-ups. this is performed by clearing bit, rbpu (intcon2<7>). the weak pull-up is automatically turned off when the port pin is configured as an output. the pull-ups are disabled on a power-on reset. pins rb0, rb1 and rb4:rb7 are multiplexed with the power control pwm outputs. pins rb2 and rb3 are multiplexed with external interrupt inputs, interrupt-on-change input, the analog comparator inputs and the timer1 oscillator input and output to become rb2/int2/kbi2/cmp2/t1oso/t1cki and rb3/int3/knbi3/cmp1/t1osi respectively. when the interrupt-on-change feature is enabled, only pins configured as inputs can cause this interrupt to occur (i.e., any rb2, rb3, ra0 and ra1 pin configured as an output is excluded from the interrupt-on-change comparison). the input pins (rb2, rb3, ra0 and ra1) are compared with the old value latched on the last read of porta and portb. the ?mismatch? outputs of these pins are ored together to generate the rb port change interrupt with flag bit, rbif (intcon<0>). this interrupt can wake the device from sleep mode, or any of the idle modes. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of porta and/or portb (except with the movff (any), porta and movff (any), portb instructions). b) clear flag bit, rbif. a mismatch condition will continue to set flag bit, rbif. reading porta and portb will end the mismatch condition and allow flag bit, rbif, to be cleared. the interrupt-on-change feature is recommended for wake-up on key depression operation and operations where porta and portb are used for the interrupt- on-change feature. polling of porta and portb is not recommended while using the interrupt-on-change feature. note: on a power-on reset, portb is configured as digital inputs except for rb2 and rb3. rb2 and rb3 are configured as analog inputs when the t1oscmx bit of configu- ration register 3h is cleared. otherwise, rb2 and rb3 are also configured as digital inputs. clrf portb ; initialize portb by ; clearing output ; data latches clrf latb ; alternate method ; to clear output ; data latches movlw 0fh ; set rb<4:0> as movwf adcon1 ; digital i/o pins ; (required if config bit ; pbaden is set) movlw 0cfh ; value used to ; initialize data ; direction movwf trisb ; set rb<3:0> as inputs ; rb<5:4> as outputs ; rb<7:6> as inputs
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 85 table 9-3: portb i/o summary pin function tris setting i/o i/o type description rb0/pwm0 rb0 0 o dig latb<0> data output; not affected by analog input. 1 i ttl portb<0> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) pwm0 0 o dig pwm module output pwm0. rb1pwm1 rb1 0 o dig latb<1> data output; not affected by analog input. 1 i ttl portb<1> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) pwm1 0 o dig pwm module output pwm1. rb2/int2/kbi2/ cmp2/t1oso/ t1cki rb2 0 o dig latb<2> data output; not affected by analog input. 1 i ttl portb<2> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) int2 1 i st external interrupt 2 input. kbi2 1 i ttl interrupt-on-change pin. cmp2 1 i ana comparator 2 input. t1oso (2) 0 o ana timer1 oscillator output. t1cki (2) 1 i st timer1 clock input. rb3/int3/kbi3/ cmp1/t1osi rb3 0 o dig latb<3> data output; not affected by analog input. 1 i ttl portb<3> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) int3 1 i st external interrupt 3 input. kbi3 1 i ttl interrupt-on-change pin. cmp1 1 i ana comparator 1 input. t1osi (2) 1 i ana timer1 oscillator input. rb4/pwm2 rb4 0 o dig latb<4> data output; not affected by analog input. 1 i ttl portb<4> data input; weak pull-up when rbpu bit is cleared. disabled when analog input enabled. (1) pwm2 0 o dig pwm module output pwm2. rb5/pwm3 rb5 0 o dig latb<5> data output. 1 i ttl portb<5> data input; weak pull-up when rbpu bit is cleared. pwm3 0 o dig pwm module output pwm3. rb6/pwm4/pgc rb6 0 o dig latb<6> data output. 1 i ttl portb<6> data input; weak pull-up when rbpu bit is cleared. pwm4 0 o dig pwm module output pwm4. pgc 1 i st in-circuit debugger and icsp? programming clock pin. rb7/pwm5/pgd rb7 0 o dig latb<7> data output. 1 i ttl portb<7> data input; weak pull-up when rbpu bit is cleared. pwm5 0 o ttl pwm module output pwm4. pgd 0 o dig in-circuit debugger and icsp programming data pin. legend: dig = digital level output; ttl = ttl input buffer; st = schmitt trigger input buffer; ana = analog level input/output; x = don?t care (tris bit does not affect port direction or is overridden for this option). note 1: configuration on por is determined by the pbaden configur ation bit. pins are configured as analog inputs by default when pbaden is set and digital inputs when pbaden is cleared. 2: placement of t1osi and t1oso/t1cki depends on the value of configuration bit, t1oscmx, of config3h.
pic18f1230/1330 ds39758b-page 86 advance information ? 2006 microchip technology inc. table 9-4: summary of registers associated with portb name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 44 latb portb data latch register (read and write to data latch) 43 trisb portb data direction control register 43 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 intcon2 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip 41 intcon3 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if 41 cmcon c2out c1out c0out ? ? cmen2 cmen1 cmen0 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by portb.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 87 10.0 interrupts the pic18f1230/1330 devices have multiple interrupt sources and an interrupt priority feature that allows most interrupt sources to be assigned a high priority level or a low priority level. the high priority interrupt vector is at 0008h and the low priority interrupt vector is at 0018h. high priority interrupt events will interrupt any low priority interrupts that may be in progress. there are thirteen registers which are used to control interrupt operation. these registers are: ? rcon ?intcon ? intcon2 ? intcon3 ? pir1, pir2, pir3 ? pie1, pie2, pie3 ? ipr1, ipr2, ipr3 it is recommended that the microchip header files supplied with mplab ? ide be used for the symbolic bit names in these registers. this allows the assembler/ compiler to automatically take care of the placement of these bits within the specified register. in general, interrupt sources have three bits to control their operation. they are: ? flag bit to indicate that an interrupt event occurred ? enable bit that allows program execution to branch to the interrupt vector address when the flag bit is set ? priority bit to select high priority or low priority the interrupt priority feature is enabled by setting the ipen bit (rcon<7>). when interrupt priority is enabled, there are two bits which enable interrupts globally. setting the gieh bit (intcon<7>) enables all interrupts that have the priority bit set (high priority). setting the giel bit (intcon<6>) enables all interrupts that have the priority bit cleared (low priority). when the interrupt flag, enable bit and appropriate global interrupt enable bit are set, the interrupt will vector immediately to address 0008h or 0018h, depending on the priority bit setting. individual interrupts can be disabled through their corresponding enable bits. when the ipen bit is cleared (default state), the interrupt priority feature is disabled and interrupts are compatible with picmicro ? mid-range devices. in compatibility mode, the interrupt priority bits for each source have no effect. intcon<6> is the peie bit, which enables/disables all peripheral interrupt sources. intcon<7> is the gie bit, which enables/disables all interrupt sources. all interrupts branch to address 0008h in compatibility mode. when an interrupt is responded to, the global interrupt enable bit is cleared to disable further interrupts. if the ipen bit is cleared, this is the gie bit. if interrupt priority levels are used, this will be either the gieh or giel bit. high priority interrupt sources can interrupt a low priority interrupt. low priority interrupts are not processed while high priority interrupts are in progress. the return address is pushed onto the stack and the pc is loaded with the interrupt vector address (0008h or 0018h). once in the interrupt service routine, the source(s) of the interrupt can be determined by polling the interrupt flag bits. the interrupt flag bits must be cleared in software before re-enabling interrupts to avoid recursive interrupts. the ?return from interrupt? instruction, retfie , exits the interrupt routine and sets the gie bit (gieh or giel if priority levels are used), which re-enables interrupts. for external interrupt events, such as the int pins or the portb input change interrupt, the interrupt latency will be three to four instruction cycles. the exact latency is the same for one or two-cycle instructions. individual interrupt flag bits are set, regardless of the status of their corresponding enable bit or the gie bit. note: do not use the movff instruction to modify any of the interrupt control registers while any interrupt is enabled. doing so may cause erratic microcontroller behavior.
pic18f1230/1330 ds39758b-page 88 advance information ? 2006 microchip technology inc. figure 10-1: pic18 interrupt logic rbie gie/gieh peie/giel wake-up if in interrupt to cpu vector to location 0008h int2if int2ie int2ip int1if int1ie int1ip tmr0if tmr0ie tmr0ip rbif rbie rbip ipen rbif rbip int2if int2ie int2ip int0if int0ie int1if int1ie peie/giel interrupt to cpu vector to location ipen ipen 0018h peripheral interrupt flag bit peripheral interrupt enable bit peripheral interrupt priority bit peripheral interrupt flag bit peripheral interrupt enable bit peripheral interrupt priority bit adif adie adip ptif ptie ptip additional peripheral interrupts adif adie adip high priority interrupt generation low priority interrupt generation ptif ptie ptip additional peripheral interrupts idle or sleep modes gie/gieh tmr0ie tmr0if tmr0ip int1ip from power control pwm interrupt logic from power control pwm interrupt logic
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 89 10.1 intcon registers the intcon registers are readable and writable registers, which contain various enable, priority and flag bits. note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling. register 10-1: intcon: interrupt control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-x gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 gie/gieh: global interrupt enable bit when ipen = 0 : 1 = enables all unmasked interrupts 0 = disables all interrupts when ipen = 1 : 1 = enables all high priority interrupts 0 = disables all interrupts bit 6 peie/giel: peripheral interrupt enable bit when ipen = 0 : 1 = enables all unmasked peripheral interrupts 0 = disables all peripheral interrupts when ipen = 1 : 1 = enables all low priority peripheral interrupts 0 = disables all low priority peripheral interrupts bit 5 tmr0ie: tmr0 overflow interrupt enable bit 1 = enables the tmr0 overflow interrupt 0 = disables the tmr0 overflow interrupt bit 4 int0ie: int0 external interrupt enable bit 1 = enables the int0 external interrupt 0 = disables the int0 external interrupt bit 3 rbie: rb port change interrupt enable bit 1 = enables the rb port change interrupt 0 = disables the rb port change interrupt bit 2 tmr0if: tmr0 overflow interrupt flag bit 1 = tmr0 register has overflowed (must be cleared in software) 0 = tmr0 register did not overflow bit 1 int0if: int0 external interrupt flag bit 1 = the int0 external interrupt occurred (must be cleared in software) 0 = the int0 external interrupt did not occur bit 0 rbif: rb port change interrupt flag bit (1) 1 = at least one of the rb7:rb4 pins changed state (must be cleared in software) 0 = none of the rb7:rb4 pins have changed state note 1: a mismatch condition will continue to set this bit. reading portb will end the mismatch condition and allow the bit to be cleared.
pic18f1230/1330 ds39758b-page 90 advance information ? 2006 microchip technology inc. register 10-2: intcon2: interrupt control register 2 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 rbpu intedg0 intedg1 intedg2 intedg3 tmr0ip int3ip rbip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rbpu : portb pull-up enable bit 1 = all portb pull-ups are disabled 0 = portb pull-ups are enabled by individual port latch values bit 6 intedg0: external interrupt 0 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 5 intedg1: external interrupt 1 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 4 intedg2: external interrupt 2 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 3 intedg3: external interrupt 3 edge select bit 1 = interrupt on rising edge 0 = interrupt on falling edge bit 2 tmr0ip: tmr0 overflow interrupt priority bit 1 = high priority 0 = low priority bit 1 int3ip: int3 external interrupt priority bit 1 = high priority 0 = low priority bit 0 rbip: rb port change interrupt priority bit 1 = high priority 0 = low priority note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 91 register 10-3: intcon3: interrupt control register 3 r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 int2ip int1ip int3ie int2ie int1ie int3if int2if int1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 int2ip: int2 external interrupt priority bit 1 = high priority 0 = low priority bit 6 int1ip: int1 external interrupt priority bit 1 = high priority 0 = low priority bit 5 int3ie: int3 external interrupt enable bit 1 = enables the int3 external interrupt 0 = disables the int3 external interrupt bit 4 int2ie: int2 external interrupt enable bit 1 = enables the int2 external interrupt 0 = disables the int2 external interrupt bit 3 int1ie: int1 external interrupt enable bit 1 = enables the int1 external interrupt 0 = disables the int1 external interrupt bit 2 int3if: int3 external interrupt flag bit 1 = the int3 external interrupt occurred (must be cleared in software) 0 = the int3 external interrupt did not occur bit 1 int2if: int2 external interrupt flag bit 1 = the int2 external interrupt occurred (must be cleared in software) 0 = the int2 external interrupt did not occur bit 0 int1if: int1 external interrupt flag bit 1 = the int1 external interrupt occurred (must be cleared in software) 0 = the int1 external interrupt did not occur note: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global interrupt enable bit. user software should ensure the appropriate interrupt flag bits are clear prior to enabling an interrupt. this feature allows for software polling.
pic18f1230/1330 ds39758b-page 92 advance information ? 2006 microchip technology inc. 10.2 pir registers the pir registers contain the individual flag bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt request (flag) registers (pir1, pir2 and pir3). note 1: interrupt flag bits are set when an interrupt condition occurs, regardless of the state of its corresponding enable bit or the global interrupt enable bit, gie (intcon<7>). 2: user software should ensure the appropriate interrupt flag bits are cleared prior to enabling an interrupt and after servicing that interrupt. register 10-4: pir1: peripheral interrupt request (flag) register 1 u-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 adif: a/d converter interrupt flag bit 1 = an a/d conversion completed (must be cleared in software) 0 = the a/d conversion is not complete bit 5 rcif: eusart receive interrupt flag bit 1 = the eusart receive buffer, rcreg, is full (cleared when rcreg is read) 0 = the eusart receive buffer is empty bit 4 txif: eusart transmit interrupt flag bit 1 = the eusart transmit buffer, txreg, is empty (cleared when txreg is written) 0 = the eusart transmit buffer is full bit 3 cmp2if: analog comparator 2 flag bit 1 = the output of cmp2 has changed since last read 0 = the output of cmp2 has not changed since last read bit 2 cmp1if: analog comparator 1 flag bit 1 = the output of cmp1 has changed since last read 0 = the output of cmp1 has not changed since last read bit 1 cmp0if: analog comparator 0 flag bit 1 = the output of cmp0 has changed since last read 0 = the output of cmp0 has not changed since last read bit 0 tmr1if: tmr1 overflow interrupt flag bit 1 = tmr1 register overflowed (must be cleared in software) 0 = tmr1 register did not overflow
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 93 register 10-5: pir2: peripheral interrupt request (flag) register 2 r/w-0 u-0 u-0 r/w-0 u-0 r/w-0 u-0 u-0 oscfif ? ? eeif ?lvdif ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfif: oscillator fail interrupt flag bit 1 = device oscillator failed, clock input has changed to intosc (must be cleared in software) 0 = device clock operating bit 6-5 unimplemented: read as ? 0 ? bit 4 eeif: data eeprom/flash write operation interrupt flag bit 1 = the write operation is complete (must be cleared in software) 0 = the write operation is not complete or has not been started bit 3 unimplemented: read as ? 0 ? bit 2 lvdif: low-voltage detect interrupt flag bit 1 = a low-voltage condition occurred 0 = a low-voltage condition has not occurred bit 1-0 unimplemented: read as ? 0 ? register 10-6: pir3: peripheral interrupt request (flag) register 3 u-0 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 ? ? ?ptif ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 ptif: pwm time base interrupt bit 1 = pwm time base matched the value in ptper register. interrupt is issued according to the postscaler settings. ptif must be cleared in software. 0 = pwm time base has not matched the value in ptper register bit 3-0 unimplemented: read as ? 0 ?
pic18f1230/1330 ds39758b-page 94 advance information ? 2006 microchip technology inc. 10.3 pie registers the pie registers contain the individual enable bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt enable registers (pie1, pie2 and pie3). when ipen = 0 , the peie bit must be set to enable any of these peripheral interrupts. register 10-7: pie1: peripheral interrupt enable register 1 u-0 r/w-0 r-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 adie: a/d converter interrupt enable bit 1 = enables the a/d interrupt 0 = disables the a/d interrupt bit 5 rcie: eusart receive interrupt enable bit 1 = enables the eusart receive interrupt 0 = disables the eusart receive interrupt bit 4 txie: eusart transmit interrupt enable bit 1 = enables the eusart transmit interrupt 0 = disables the eusart transmit interrupt bit 3 cmp2ie: analog comparator 2 interrupt enable bit 1 = enables the cmp2 interrupt 0 = disables the cmp2 interrupt bit 2 cmp1ie: analog comparator 1 interrupt enable bit 1 = the output of cmp1 has changed since last read 0 = the output of cmp1 has not changed since last read bit 1 cmp0ie: analog comparator 0 interrupt enable bit 1 = the output of cmp0 has changed since last read 0 = the output of cmp0 has not changed since last read bit 0 tmr1ie: tmr1 overflow interrupt enable bit 1 = enables the tmr1 overflow interrupt 0 = disables the tmr1 overflow interrupt
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 95 register 10-8: pie2: peripheral interrupt enable register 2 r/w-0 u-0 u-0 r/w-0 u-0 r/w-0 u-0 u-0 oscfie ? ? eeie ?lvdie ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfie: oscillator fail interrupt enable bit 1 = enabled 0 =disabled bit 6-5 unimplemented: read as ? 0 ? bit 4 eeie: data eeprom/flash write operation interrupt enable bit 1 = enabled 0 =disabled bit 3 unimplemented: read as ? 0 ? bit 2 lvdie: low-voltage detect interrupt enable bit 1 = enabled 0 =disabled bit 1-0 unimplemented: read as ? 0 ? register 10-9: pie3: peripheral interrupt enable register 3 u-0 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 ? ? ?ptie ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 ptie: pwm time base interrupt enable bit 1 = pwm enabled 0 = pwm disabled bit 3-0 unimplemented: read as ? 0 ?
pic18f1230/1330 ds39758b-page 96 advance information ? 2006 microchip technology inc. 10.4 ipr registers the ipr registers contain the individual priority bits for the peripheral interrupts. due to the number of peripheral interrupt sources, there are three peripheral interrupt priority registers (ipr1, ipr2 and ipr3). using the priority bits requires that the interrupt priority enable (ipen) bit be set. register 10-10: ipr1: peripheral interrupt priority register 1 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6 adip: a/d converter interrupt priority bit 1 = high priority 0 = low priority bit 5 rcip: eusart receive interrupt priority bit 1 = high priority 0 = low priority bit 4 txip: eusart transmit interrupt priority bit 1 = high priority 0 = low priority bit 3 cmp2ip: analog comparator 2 interrupt priority bit 1 = enables the cmp2 interrupt 0 = disables the cmp2 interrupt bit 2 cmp1ip: analog comparator 1 interrupt priority bit 1 = the output of cmp1 has changed since last read 0 = the output of cmp1 has not changed since last read bit 1 cmp0ip: analog comparator 0 interrupt priority bit 1 = the output of cmp0 has changed since last read 0 = the output of cmp0 has not changed since last read bit 0 tmr1ip: tmr1 overflow interrupt priority bit 1 = high priority 0 = low priority
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 97 register 10-11: ipr2: peripheral interrupt priority register 2 r/w-1 u-0 u-0 r/w-1 u-0 r/w-1 u-0 u-0 oscfip ? ? eeip ?lvdip ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 oscfip: oscillator fail interrupt priority bit 1 = high priority 0 = low priority bit 6-5 unimplemented: read as ? 0 ? bit 4 eeip: data eeprom/flash write operation interrupt priority bit 1 = high priority 0 = low priority bit 3 unimplemented: read as ? 0 ? bit 2 lvdip: low-voltage detect interrupt priority bit 1 = high priority 0 = low priority bit 1-0 unimplemented: read as ? 0 ? register 10-12: ipr3: peripheral interrupt priority register 3 u-0 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 ? ? ?ptip ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 ptip: pwm time base interrupt priority bit 1 = high priority 0 = low priority bit 3-0 unimplemented: read as ? 0 ?
pic18f1230/1330 ds39758b-page 98 advance information ? 2006 microchip technology inc. 10.5 rcon register the rcon register contains flag bits which are used to determine the cause of the last reset or wake-up from idle or sleep modes. rcon also contains the ipen bit which enables interrupt priorities. the operation of the sboren bit and the reset flag bits is discussed in more detail in section 4.1 ?rcon register? . register 10-13: rcon: reset control register r/w-0 r/w-1 (1) u-0 r/w-1 r-1 r-1 r/w-0 (2) r/w-0 ipen sboren ?ri to pd por bor bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ipen: interrupt priority enable bit 1 = enable priority levels on interrupts 0 = disable priority levels on interrupts (pic16cxxx compatibility mode) bit 6 sboren: bor software enable bit (1) for details of bit operation, see register 4-1. bit 5 unimplemented: read as ? 0 ? bit 4 ri : reset instruction flag bit for details of bit operation, see register 4-1. bit 3 to : watchdog time-out flag bit for details of bit operation, see register 4-1. bit 2 pd : power-down detection flag bit for details of bit operation, see register 4-1. bit 1 por : power-on reset status bit (2) for details of bit operation, see register 4-1. bit 0 bor : brown-out reset status bit for details of bit operation, see register 4-1. note 1: if sboren is enabled, its reset state is ? 1 ?; otherwise, it is ? 0 ?. see register 4-1 for additional information. 2: the actual reset value of por is determined by the type of device reset. see register 4-1 for additional information.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 99 10.6 intn pin interrupts external interrupts on the ra0/int0, ra1/int1, rb2/ int2 and rb3/int3 pins are edge-triggered. if the corresponding intedgx bit in the intcon2 register is set (= 1 ), the interrupt is triggered by a rising edge; if the bit is clear, the trigger is on the falling edge. when a valid edge appears on the pin, the corresponding flag bit, intxif, is set. this interrupt can be disabled by clearing the corresponding enable bit, intxie. flag bit, intxif, must be cleared in software in the interrupt service routine before re-enabling the interrupt. all external interrupts (int0, int1, int2 and int3) can wake-up the processor from idle or sleep modes if bit intxie was set prior to going into those modes. if the global interrupt enable bit, gie, is set, the processor will branch to the interrupt vector following wake-up. interrupt priority for int1, int2 and int3 is determined by the value contained in the interrupt priority bits, int1ip (intcon3<6>), int2ip (intcon3<7>) and int3ip (intcon2<1>). there is no priority bit associated with int0. it is always a high priority interrupt source. 10.7 tmr0 interrupt in 8-bit mode (which is the default), an overflow in the tmr0 register (ffh 00h) will set flag bit, tmr0if. in 16-bit mode, an overflow in the tmr0h:tmr0l register pair (ffffh 0000h) will set tmr0if. the interrupt can be enabled/disabled by setting/clearing enable bit, tmr0ie (intcon<5>). interrupt priority for timer0 is determined by the value contained in the interrupt priority bit, tmr0ip (intcon2<2>). see section 11.0 ?timer0 module? for further details on the timer0 module. 10.8 interrupt-on-change an input change on porta<1:0> and/or portb<2:3> sets flag bit, rbif (intcon<0>). the interrupt can be enabled/disabled by setting/clearing enable bit, rbie (intcon<3>). interrupt priority for interrupt-on-change is determined by the value contained in the interrupt priority bit, rbip (intcon2<0>). 10.9 context saving during interrupts during interrupts, the return pc address is saved on the stack. additionally, the wreg, status and bsr registers are saved on the fast return stack. if a fast return from interrupt is not used (see section 5.3 ?data memory organization? ), the user may need to save the wreg, status and bsr registers on entry to the interrupt service routine. depending on the user?s application, other registers may also need to be saved. example 10-1 saves and restores the wreg, status and bsr registers during an interrupt service routine. example 10-1: saving status, wreg and bsr registers in ram movwf w_temp ; w_temp is in virtual bank movff status, status_temp ; status_temp located anywhere movff bsr, bsr_temp ; bsr_tmep located anywhere ; ; user isr code ; movff bsr_temp, bsr ; restore bsr movf w_temp, w ; restore wreg movff status_temp, status ; restore status
pic18f1230/1330 ds39758b-page 100 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 101 11.0 timer0 module the timer0 module has the following features: ? software selectable as an 8-bit or 16-bit timer/counter ? readable and writable ? dedicated 8-bit software programmable prescaler ? clock source selectable to be external or internal ? interrupt on overflow from ffh to 00h in 8-bit mode and ffffh to 0000h in 16-bit mode ? edge select for external clock figure 11-1 shows a simplified block diagram of the timer0 module in 8-bit mode and figure 11-2 shows a simplified block diagram of the timer0 module in 16-bit mode. the t0con register (register 11-1) is a readable and writable register that controls all the aspects of timer0, including the prescale selection. register 11-1: t0con: timer0 control register r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 tmr0on t016bit t0cs t0se psa t0ps2 t0ps1 t0ps0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 tmr0on: timer0 on/off control bit 1 = enables timer0 0 = stops timer0 bit 6 t016bit : timer0 16-bit control bit 1 = timer0 is configured as an 8-bit timer/counter 0 = timer0 is configured as a 16-bit timer/counter bit 5 t0cs : timer0 clock source select bit 1 = transition on t0cki pin 0 = internal instruction cycle clock (clko) bit 4 t0se : timer0 source edge select bit 1 = increment on high-to-low transition on t0cki pin 0 = increment on low-to-high transition on t0cki pin bit 3 psa : timer0 prescaler assignment bit 1 = timer0 prescaler is not assigned. timer0 clock input bypasses prescaler. 0 = timer0 prescaler is assigned. timer0 clock input comes from prescaler output. bit 2-0 t0ps2:t0ps0 : timer0 prescaler select bits 111 = 1:256 prescale value 110 = 1:128 prescale value 101 = 1:64 prescale value 100 = 1:32 prescale value 011 = 1:16 prescale value 010 = 1:8 prescale value 001 = 1:4 prescale value 000 = 1:2 prescale value
pic18f1230/1330 ds39758b-page 102 advance information ? 2006 microchip technology inc. figure 11-1: timer0 block diagram in 8-bit mode figure 11-2: timer0 block diagram in 16-bit mode note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki maximum prescale. t0cki pin t0se 0 1 1 0 t0cs f osc /4 programmable prescaler tmr0 (2 t cy delay) data bus 8 psa t0ps2, t0ps1, t0ps0 set interrupt flag bit tmr0if on overflow 3 sync with internal clocks note: upon reset, timer0 is enabled in 8-bit mode with clock input from t0cki maximum prescale. t0se 0 1 1 0 t0cs f osc /4 programmable prescaler sync with internal clocks tmr0l (2 t cy delay) data bus<7:0> 8 psa t0ps2, t0ps1, t0ps0 set interrupt flag bit tmr0if on overflow 3 tmr0 tmr0h high byte 8 8 8 read tmr0l write tmr0l t0cki pin
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 103 11.1 timer0 operation timer0 can operate as a timer or as a counter. timer mode is selected by clearing the t0cs bit. in timer mode, the timer0 module will increment every instruction cycle (without prescaler). if the tmr0 register is written, the increment is inhibited for the following two instruction cycles. the user can work around this by writing an adjusted value to the tmr0 register. counter mode is selected by setting the t0cs bit. in counter mode, timer0 will increment, either on every rising or falling edge of pin ra4/t0cki/an2/v ref +. the incrementing edge is determined by the timer0 source edge select bit (t0se). clearing the t0se bit selects the rising edge. when an external clock input is used for timer0, it must meet certain requirements. the requirements ensure the external clock can be synchronized with the internal phase clock (t osc ). also, there is a delay in the actual incrementing of timer0 after synchronization. 11.2 prescaler an 8-bit counter is available as a prescaler for the timer0 module. the prescaler is not readable or writable. the psa and t0ps2:t0ps0 bits determine the prescaler assignment and prescale ratio. clearing bit psa will assign the prescaler to the timer0 module. when the prescaler is assigned to the timer0 module, prescale values of 1:2, 1:4, ..., 1:256 are selectable. when assigned to the timer0 module, all instructions writ- ing to the tmr0 register (e.g., clrf tmr0 , movwf tmr0 , bsf tmr0, x ..., etc.) will clear the prescaler count. 11.2.1 switching prescaler assignment the prescaler assignment is fully under software control (i.e., it can be changed ?on-the-fly? during program execution). 11.3 timer0 interrupt the tmr0 interrupt is generated when the tmr0 register overflows from ffh to 00h in 8-bit mode, or ffffh to 0000h in 16-bit mode. this overflow sets the tmr0if bit. the interrupt can be masked by clearing the tmr0ie bit. the tmr0if bit must be cleared in software by the timer0 module interrupt service routine before re-enabling this interrupt. the tmr0 interrupt cannot awaken the processor from sleep mode, since the timer requires clock cycles even when t0cs is set. 11.4 16-bit mode timer reads and writes tmr0h is not the high byte of the timer/counter in 16-bit mode, but is actually a buffered version of the high byte of timer0 (refer to figure 11-2). the high byte of the timer0 counter/timer is not directly readable nor writable. tmr0h is updated with the contents of the high byte of timer0 during a read of tmr0l. this provides the ability to read all 16 bits of timer0 without having to verify that the read of the high and low byte were valid due to a rollover between successive reads of the high and low byte. a write to the high byte of timer0 must also take place through the tmr0h buffer register. timer0 high byte is updated with the contents of tmr0h when a write occurs to tmr0l. this allows all 16 bits of timer0 to be updated at once. table 11-1: registers associated with timer0 note: writing to tmr0, when the prescaler is assigned to timer0, will clear the prescaler count but will not change the prescaler assignment. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page tmr0l timer0 register low byte 42 tmr0h timer0 register high byte 42 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 t0con tmr0on t016bit t0cs t0se psa t0ps2 t0ps1 t0ps0 42 trisa ra7 (1) ra6 (1) porta data direction control register 43 legend: x = unknown, u = unchanged, ? = unimplemented locations read as ? 0 ?. shaded cells are not used by timer0. note 1: ra6 and ra7 are enabled as i/o pins depending on the oscillator mode selected in config1h.
pic18f1230/1330 ds39758b-page 104 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 105 12.0 timer1 module the timer1 timer/counter module has the following features: ? 16-bit timer/counter (two 8-bit registers; tmr1h and tmr1l) ? readable and writable (both registers) ? internal or external clock select ? interrupt on overflow from ffffh to 0000h ? status of system clock operation figure 12-1 is a simplified block diagram of the timer1 module. register 12-1 details the timer1 control register. this register controls the operating mode of the timer1 module and contains the timer1 oscillator enable bit (t1oscen). timer1 can be enabled or disabled by setting or clearing control bit, tmr1on (t1con<0>). the timer1 oscillator can be used as a secondary clock source in power-managed modes. when the t1run bit is set, the timer1 oscillator provides the system clock. if the fail-safe clock monitor is enabled and the timer1 oscillator fails while providing the system clock, polling the t1run bit will indicate whether the clock is being provided by the timer1 oscillator or another source. timer1 can also be used to provide real-time clock (rtc) functionality to applications with only a minimal addition of external components and code overhead. register 12-1: t1con: ti mer1 control register r/w-0 r-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 rd16: 16-bit read/write mode enable bit 1 = enables register read/write of timer1 in one 16-bit operation 0 = enables register read/write of timer1 in two 8-bit operations bit 6 t1run: timer1 system clock status bit 1 = device clock is derived from timer1 oscillator 0 = device clock is derived from another source bit 5-4 t1ckps1:t1ckps0: timer1 input clock prescale select bits 11 = 1:8 prescale value 10 = 1:4 prescale value 01 = 1:2 prescale value 00 = 1:1 prescale value bit 3 t1oscen: timer1 oscillator enable bit 1 = timer1 oscillator is enabled 0 = timer1 oscillator is shut off the oscillator inverter and feedback resistor are turned off to eliminate power drain. bit 2 t1sync : timer1 external clock input synchronization select bit when tmr1cs = 1 : 1 = do not synchronize external clock input 0 = synchronize external clock input when tmr1cs = 0 : this bit is ignored. timer1 uses the internal clock when tmr1cs = 0 . bit 1 tmr1cs: timer1 clock source select bit 1 = external clock from t1oso/t1cki (on the rising edge) (1) 0 = internal clock (f osc /4) bit 0 tmr1on: timer1 on bit 1 = enables timer1 0 = stops timer1 note 1: placement of t1osi and t1oso/t1cki depends on the value of the configuration bit, t1oscmx, of config3h.
pic18f1230/1330 ds39758b-page 106 advance information ? 2006 microchip technology inc. 12.1 timer1 operation timer1 can operate in one of these modes: ?as a timer ? as a synchronous counter ? as an asynchronous counter the operating mode is determined by the clock select bit, tmr1cs (t1con<1>). when tmr1cs = 0 , timer1 increments every instruction cycle. when tmr1cs = 1 , timer1 increments on every rising edge of the external clock input or the timer1 oscillator, if enabled. when the timer1 oscillator is enabled (t1oscen is set), the t1osi and t1oso/t1cki pins become inputs. that is, the corresponding trisa bit value is ignored, and the pins are read as ? 0 ?. figure 12-1: timer1 block diagram figure 12-2: timer1 block diag ram: 16-bit read/write mode t1osc tmr1h tmr1l t1sync tmr1cs t1ckps1:t1ckps0 peripheral clocks f osc /4 internal clock tmr1on on/off synchronize det 1 0 0 1 synchronized clock input 2 tmr1if overflow tmr1 t1oscen enable oscillator (1) interrupt flag bit note 1: when enable bit t1oscen is cleared, the inverter and feedback re sistor are turned off. this eliminates power drain. t1osi t1oso/t1cki prescaler 1, 2, 4, 8 timer1 tmr1l t1osc t1sync tmr1cs t1ckps1:t1ckps0 peripheral clocks t1oscen enable oscillator (1) tmr1if overflow interrupt f osc /4 internal clock tmr1on on/off prescaler 1, 2, 4, 8 synchronize det 1 0 0 1 synchronized clock input 2 t1oso/t1cki t1osi tmr1 flag bit note 1: when enable bit t1oscen is cleared, the inverter and feedback resistor are turned off. th is eliminates power drain. high byte data bus<7:0> 8 tmr1h 8 8 8 read tmr1l write tmr1l
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 107 12.2 timer1 oscillator a crystal oscillator circuit is built-in between pins t1osi (input) and t1oso/ticki (amplifier output). the place- ment of these pins depends on the value of configuration bit, t1oscmx (see section 19.1 ?configuration bits? ). it is enabled by setting control bit t1oscen (t1con<3>). the oscillator is a low-power oscillator rated for 32 khz crystals. it will continue to run during all power-managed modes. the circuit for a typical lp oscillator is shown in figure 12-3. table 12-1 shows the capacitor selection for the timer1 oscillator. the user must provide a software time delay to ensure proper start-up of the timer1 oscillator. figure 12-3: external components for the timer1 lp oscillator table 12-1: capacitor selection for the timer oscillator 12.2.1 using timer1 as a clock source the timer1 oscillator is also available as a clock source in power-managed modes. by setting the system clock select bits, scs1:scs0 (osccon<1:0>), to ? 01 ?, the device switches to sec_run mode; both the cpu and peripherals are clocked from the timer1 oscil- lator. if the idlen bit (osccon<7>) is cleared and a sleep instruction is executed, the device enters sec_idle mode. additional details are available in section 3.0 ?power-managed modes? . whenever the timer1 oscillator is providing the clock source, the timer1 system clock status flag, t1run (t1con<6>), is set. this can be used to determine the controller?s current clocking mode. it can also indicate the clock source being currently used by the fail-safe clock monitor. if the clock monitor is enabled and the timer1 oscillator fails while providing the clock, polling the t1run bit will indicate whether the clock is being provided by the timer1 oscillator or another source. 12.3 timer1 oscillator layout considerations the oscillator circuit, shown in figure 12-3, should be located as close as possible to the microcontroller. there should be no circuits passing within the oscillator circuit boundaries other than v ss or v dd . if a high-speed circuit must be located near the oscillator (such as the pwm pin, or the primary oscillator using the osc2 pin), a grounded guard ring around the oscillator circuit, as shown in figure 12-4, may be helpful when used on a single-sided pcb, or in addition to a ground plane. figure 12-4: oscillator circuit with grounded guard ring osc type freq c1 c2 lp 32 khz 27 pf (1) 27 pf (1) note 1: microchip suggests this value as a starting point in validating the oscillator circuit. 2: higher capacitance increases the stability of the oscillator, but also increases the start-up time. 3: since each resonator/crystal has its own characteristics, the user should consult the resonator/crystal manufacturer for appropriate values of external components. 4: capacitor values are for design guidance only. note: see the notes with table 12-1 for addi- tional information about capacitor selec- c1 c2 xtal pic18fxxxx t1osi t1oso/t1cki 32.768 khz 33 pf 33 pf rb3 rb2 osc1 osc2 v dd note: not drawn to scale.
pic18f1230/1330 ds39758b-page 108 advance information ? 2006 microchip technology inc. 12.4 timer1 interrupt the tmr1 register pair (tmr1h:tmr1l) increments from 0000h to ffffh and rolls over to 0000h. the timer1 interrupt, if enabled, is generated on overflow which is latched in interrupt flag bit, tmr1if (pir1<0>). this interrupt can be enabled/disabled by setting/clearing timer1 interrupt enable bit, tmr1ie (pie1<0>). 12.5 timer1 16-bit read/write mode timer1 can be configured for 16-bit reads and writes (see figure 12-2). when the rd16 control bit (t1con<7>) is set, the address for tmr1h is mapped to a buffer register for the high byte of timer1. a read from tmr1l will load the contents of the high byte of timer1 into the timer1 high byte buffer register. this provides the user with the ability to accurately read all 16 bits of timer1 without having to determine whether a read of the high byte, followed by a read of the low byte, is valid due to a rollover between reads. a write to the high byte of timer1 must also take place through the tmr1h buffer register. timer1 high byte is updated with the contents of tmr1h when a write occurs to tmr1l. this allows a user to write all 16 bits to both the high and low bytes of timer1 at once. the high byte of timer1 is not directly readable or writable in this mode. all reads and writes must take place through the timer1 high byte buffer register. writes to tmr1h do not clear the timer1 prescaler. the prescaler is only cleared on writes to tmr1l. 12.6 using timer1 as a real-time clock adding an external lp oscillator to timer1 (such as the one described in section 12.2 ?timer1 oscillator? ), gives users the option to include rtc functionality to their applications. this is accomplished with an inexpensive watch crystal to provide an accurate time base and several lines of application code to calculate the time. when operating in sleep mode and using a battery or super capacitor as a power source, it can completely eliminate the need for a separate rtc device and battery backup. the application code routine, rtcisr , shown in example 12-1, demonstrates a simple method to increment a counter at one-second intervals using an interrupt service routine. incrementing the tmr1 register pair to overflow triggers the interrupt and calls the routine, which increments the seconds counter by one. additional counters for minutes and hours are incremented as the previous counter overflow. since the register pair is 16 bits wide, counting up to overflow the register directly from a 32.768 khz clock would take 2 seconds. to force the overflow at the required one-second intervals, it is necessary to pre- load it. the simplest method is to set the msb of tmr1h with a bsf instruction. note that the tmr1l register is never preloaded or altered; doing so may introduce cumulative error over many cycles. for this method to be accurate, timer1 must operate in asynchronous mode and the timer1 overflow interrupt must be enabled (pie1<0> = 1 ), as shown in the routine, rtcinit . the timer1 oscillator must also be enabled and running at all times.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 109 example 12-1: implementing a real-time clock using a timer1 interrupt service table 12-2: registers associated with timer1 as a timer/counter rtcinit movlw 0x80 ; preload tmr1 register pair movwf tmr1h ; for 1 second overflow clrf tmr1l movlw b?00001111? ; configure for external clock, movwf t1osc ; asynchronous operation, external oscillator clrf secs ; initialize timekeeping registers clrf mins ; movlw .12 movwf hours bsf pie1, tmr1ie ; enable timer1 interrupt return rtcisr bsf tmr1h, 7 ; preload for 1 sec overflow bcf pir1, tmr1if ; clear interrupt flag incf secs, f ; increment seconds movlw .59 ; 60 seconds elapsed? cpfsgt secs return ; no, done clrf secs ; clear seconds incf mins, f ; increment minutes movlw .59 ; 60 minutes elapsed? cpfsgt mins return ; no, done clrf mins ; clear minutes incf hours, f ; increment hours movlw .23 ; 24 hours elapsed? cpfsgt hours return ; no, done movlw .01 ; reset hours to 1 movwf hours return ; done name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 tmr1l timer1 register low byte 42 tmr1h timer1 register high byte 42 t1con rd16 t1run t1ckps1 t1ckps0 t1oscen t1sync tmr1cs tmr1on 42 legend: x = unknown, u = unchanged, ? = unimplemented, read as ? 0 ?. shaded cells are not used by the timer1 module.
pic18f1230/1330 ds39758b-page 110 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 111 13.0 power control pwm module the power control pwm module simplifies the task of generating multiple, synchronized pulse-width modulated (pwm) outputs for use in the control of motor controllers and power conversion applications. in particular, the following power and motion control applications are supported by the pwm module: ? three-phase and single-phase ac induction motors ? switched reluctance motors ? brushless dc (bldc) motors ? uninterruptible power supplies (ups) ? multiple dc brush motors the pwm module has the following features: ? up to six pwm i/o pins with three duty cycle generators. pins can be paired to acquire a complete half-bridge control. ? up to 14-bit resolution, depending upon the pwm period. ? ?on-the-fly? pwm frequency changes. ? edge and center-aligned output modes. ? single-pulse generation mode. ? programmable dead-time control between paired pwms. ? interrupt support for asymmetrical updates in center-aligned mode. ? output override for electrically commutated motor (ecm) operation; for example, bldc. ? special event trigger comparator for triggering a/d conversion. ? pwm outputs disable feature sets pwm outputs to their inactive state when in debug mode. the power control pwm module supports three pwm generators and six output channels on pic18f1230/ 1330 devices. a simplified block diagram of the module is shown in figure 13-1. figure 13-2 and figure 13-3 show how the module hardware is configured for each pwm output pair for the complementary and independent output modes. each functional unit of the pwm module will be discussed in subsequent sections.
pic18f1230/1330 ds39758b-page 112 advance information ? 2006 microchip technology inc. figure 13-1: power control pwm module block diagram pdc2 pdc2 buffer output driver block pwmcon0 ptper buffer pwmcon1 ptper ptmr comparator comparator channel 2 ptconx sevtcmp comparator special event trigger ovdcon pwm enable and mode pwm manual control pwm pwm pwm generator #2 (1) sevtdir ptdir dtcon dead-time control special event postscaler flta pwm0 pwm1 pwm2 pwm3 note 1: only pwm generator 2 is shown in detail. the other generat ors are identical; their detai ls are omitted for clarity. pwm4 pwm5 fltconfig fault pin control dead-time generator and override logic (1) channel 1 dead-time generator and override logic channel 0 dead-time generator and override logic internal data bus 8 8 8 8 8 8 8 8 8 8 generator 0 generator 1
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 113 figure 13-2: pwm module block diagram, one output pair, complementary mode figure 13-3: pwm module bl ock diagram, one output pair, independent mode this module contains three duty cycle generators, numbered 0 through 2. the module has six pwm output pins, numbered 0 through 5. the six pwm outputs are grouped into output pairs of even and odd numbered outputs. in complementary modes, the even pwm pins must always be the complement of the corresponding odd pwm pins. for example, pwm0 will be the complement of pwm1 and pwm2 will be the complement of pwm3. the dead-time generator inserts an off period called ?dead time? between the going off of one pin to the going on of the complementary pin of the paired pins. this is to prevent damage to the power switching devices that will be connected to the pwm output pins. the time base for the pwm module is provided by its own 12-bit timer, which also incorporates selectable prescaler and postscaler options. pwm duty cycle register duty cycle comparator dead-band generator fault override values channel override values fault pin assignment logic fault a pin hpol lpol pwm1 pwm0 v dd note: in the complementary mode, the even channel cannot be forced active by a fault or override event when the odd channel is active. the even channel is always the complement of the odd channel and is inactive, with dead time inserted, before the odd channel is driven to its active state. duty cycle comparator pwm duty cycle register fault a pin hpol lpol pwm1 pwm0 v dd v dd fault override values channel override values fault pin assignment logic
pic18f1230/1330 ds39758b-page 114 advance information ? 2006 microchip technology inc. 13.1 control registers the operation of the pwm module is controlled by a total of 20 registers. eight of these are used to configure the features of the module: ? pwm timer control register 0 (ptcon0) ? pwm timer control register 1 (ptcon1) ? pwm control register 0 (pwmcon0) ? pwm control register 1 (pwmcon1) ? dead-time control register (dtcon) ? output override control register (ovdcond) ? output state register (ovdcons) ? fault configuration register (fltconfig) there are also 12 registers that are configured as six register pairs of 16 bits. these are used for the configuration values of specific features. they are: ? pwm time base registers (ptmrh and ptmrl) ? pwm time base period registers (ptperh and ptperl) ? pwm special event compare registers (sevtcmph and sevtcmpl) ? pwm duty cycle #0 registers (pdc0h and pdc0l) ? pwm duty cycle #1 registers (pdc1h and pdc1l) ? pwm duty cycle #2 registers (pdc2h and pdc2l) all of these register pairs are double-buffered. 13.2 module functionality the pwm module supports several modes of operation that are beneficial for specific power and motor control applications. each mode of operation is described in subsequent sections. the pwm module is composed of several functional blocks. the operation of each is explained separately in relation to the several modes of operation: ?pwm time base ? pwm time base interrupts ?pwm period ? pwm duty cycle ? dead-time generators ? pwm output overrides ? pwm fault inputs ? pwm special event trigger 13.3 pwm time base the pwm time base is provided by a 12-bit timer with prescaler and postscaler functions. a simplified block diagram of the pwm time base is shown in figure 13-4. the pwm time base is configured through the ptcon0 and ptcon1 registers. the time base is enabled or disabled by respectively setting or clearing the pten bit in the ptcon1 register. note: the ptmr register pair (ptmrl:ptmrh) is not cleared when the pten bit is cleared in software.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 115 figure 13-4: pwm time base block diagram the pwm time base can be configured for four different modes of operation: ? free-running mode ? single-shot mode ? continuous up/down count mode ? continuous up/down count mode with interrupts for double updates these four modes are selected by the ptmod1:ptmod0 bits in the ptcon0 register. the free-running mode produces edge-aligned pwm generation. the continuous up/down count modes produce center-aligned pwm generation. the single- shot mode allows the pwm module to support pulse control of certain electronically commutated motors (ecms) and produces edge-aligned operation. ptmr register ptper comparator ptper buffer comparator zero match period match ptmod1 up/down timer reset f osc /4 prescaler 1:1, 1:4, 1:16, 1:64 timer direction control clock control period load duty cycle load ptmod1 period match zero match ptmr clock interrupt control ptmod1 period match zero match ptmod0 ptmod0 pten ptif ptdir ptmr clock update disable (udis) postscaler 1:1-1:16
pic18f1230/1330 ds39758b-page 116 advance information ? 2006 microchip technology inc. register 13-1: ptcon0: pwm timer control register 0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ptops3 ptops2 ptops1 ptops0 ptckps1 ptckps0 ptmod1 ptmod0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 ptops3:ptops0: pwm time base output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale . . . 1111 = 1:16 postscale bit 3-2 ptckps1:ptckps0: pwm time base input clock prescale select bits 00 = pwm time base input clock is f osc /4 (1:1 prescale) 01 = pwm time base input clock is f osc /16 (1:4 prescale) 10 = pwm time base input clock is f osc /64 (1:16 prescale) 11 = pwm time base input clock is f osc /256 (1:64 prescale) bit 1-0 ptmod1:ptmod0: pwm time base mode select bits 11 = pwm time base operates in a continuous up/down count mode with interrupts for double pwm updates 10 = pwm time base operates in a continuous up/down count mode 01 = pwm time base configured for single-shot mode 00 = pwm time base operates in a free-running mode register 13-2: ptcon1: pwm timer control register 1 r/w-0 r-0 u-0 u-0 u-0 u-0 u-0 u-0 pten ptdir ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 pten: pwm time base timer enable bit 1 = pwm time base is on 0 = pwm time base is off bit 6 ptdir: pwm time base count direction status bit 1 = pwm time base counts down 0 = pwm time base counts up bit 5-0 unimplemented: read as ? 0 ?
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 117 register 13-3: pwmcon0: pwm control register 0 u-0 r/w-1 (1) r/w-1 (1) r/w-1 (1) u-0 r/w-0 r/w-0 r/w-0 ? pwmen2 pwmen1 pwmen0 ? pmod2 pmod1 pmod0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 unimplemented: read as ? 0 ? bit 6-4 pwmen2:pwmen0: pwm module enable bits (1) 111 = all odd pwm i/o pins enabled for pwm output 110 = pwm1, pwm3 pins enabled for pwm output 10x = all pwm i/o pins enabled for pwm output 011 = pwm0, pwm1, pwm2 and pwm3 i/o pins enabled for pwm output 010 = pwm0 and pwm1 pins enabled for pwm output 001 = pwm1 pin is enabled for pwm output 000 = pwm module disabled; all pwm i/o pins are general purpose i/o bit 3 unimplemented: read as ? 0 ? bit 2-0 pmod2:pmod0: pwm output pair mode bits for pmod0 : 1 = pwm i/o pin pair (pwm0, pwm1) is in the independent mode 0 = pwm i/o pin pair (pwm0, pwm1) is in the complementary mode for pmod1: 1 = pwm i/o pin pair (pwm2, pwm3) is in the independent mode 0 = pwm i/o pin pair (pwm2, pwm3) is in the complementary mode for pmod2: 1 = pwm i/o pin pair (pwm4, pwm5) is in the independent mode 0 = pwm i/o pin pair (pwm4, pwm5) is in the complementary mode note 1: reset condition of pwmen bits depends on the pwmpin configuration bit.
pic18f1230/1330 ds39758b-page 118 advance information ? 2006 microchip technology inc. register 13-4: pwmcon1: pwm control register 1 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 sevops3 sevops2 sevops1 sevops0 sevtdir ? udis osync bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-4 sevops3:sevops0: pwm special event trigger output postscale select bits 0000 = 1:1 postscale 0001 = 1:2 postscale . . . 1111 = 1:16 postscale bit 3 sevtdir: special event trigger time base direction bit 1 = a special event trigger will occur when the pwm time base is counting downwards 0 = a special event trigger will occur when the pwm time base is counting upwards bit 2 unimplemented: read as ? 0 ? bit 1 udis: pwm update disable bit 1 = updates from duty cycle and period buffer registers are disabled 0 = updates from duty cycle and period buffer registers are enabled bit 0 osync: pwm output override synchronization bit 1 = output overrides via the ovdcon register are synchronized to the pwm time base 0 = output overrides via the ovdcon register are asynchronous
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 119 13.3.1 free-running mode in the free-running mode, the pwm time base (ptmrl and ptmrh) will begin counting upwards until the value in the pwm time base period register, ptper (ptperl and ptperh), is matched. the ptmr registers will be reset on the following input clock edge and the time base will continue counting upwards as long as the pten bit remains set. 13.3.2 single-shot mode in the single-shot mode, the pwm time base will begin counting upwards when the pten bit is set. when the value in the ptmr register matches the ptper register, the ptmr register will be reset on the following input clock edge and the pten bit will be cleared by the hardware to halt the time base. 13.3.3 continuous up/down count modes in continuous up/down count modes, the pwm time base counts upwards until the value in the ptper register matches the ptmr register. on the following input clock edge, the timer counts downwards. the ptdir bit in the ptcon1 register is read-only and indicates the counting direction. the ptdir bit is set when the timer counts downwards. 13.3.4 pwm time base prescaler the input clock to ptmr (f osc /4) has prescaler options of 1:1, 1:4, 1:16 or 1:64. these are selected by control bits, ptckps<1:0>, in the ptcon0 register. the prescaler counter is cleared when any of the following occurs: ? write to the ptmr register ? write to the ptcon (ptcon0 or ptcon1) register ? any device reset table 13-1 shows the minimum pwm frequencies that can be generated with the pwm time base and the prescaler. an operating frequency of 40 mhz (f cyc = 10 mhz) and ptper = 0xfff are assumed in the table. the pwm module must be capable of generating pwm signals at the line frequency (50 hz or 60 hz) for certain power control applications. table 13-1: minimum pwm frequency 13.3.5 pwm time base postscaler the match output of ptmr can optionally be postscaled through a 4-bit postscaler (which gives a 1:1 to 1:16 scaling inclusive) to generate an interrupt. the postscaler counter is cleared when any of the following occurs: ? write to the ptmr register ? write to the ptconx register ? any device reset the ptmr register is not cleared when ptconx is written. 13.4 pwm time base interrupts the pwm timer can generate interrupts based on the modes of operation selected by the ptmod<1:0> bits and the postscaler bits (ptops<3:0>). 13.4.1 interrupts in free-running mode when the pwm time base is in the free-running mode (ptmod<1:0> = 00 ), an interrupt event is generated each time a match with the ptper register occurs. the ptmr register is reset to zero in the following clock edge. using a postscaler selection other than 1:1 will reduce the frequency of interrupt events. note: since the pwm compare outputs are driven to the active state when the pwm time-base is counting downwards and matches the duty cycle value, the pwm outputs are held inactive during the first half of the first period of the continuous up/down count mode until the ptmr begins to count down from the ptper value. note: the ptmr register is not cleared when ptconx is written. minimum pwm frequencies vs. prescaler value for f cyc = 10 mips (ptper = 0fffh) prescale pwm frequency edge-aligned pwm frequency center-aligned 1:1 2441 hz 1221 hz 1:4 610 hz 305 hz 1:16 153 hz 76 hz 1:64 38 hz 19 hz
pic18f1230/1330 ds39758b-page 120 advance information ? 2006 microchip technology inc. figure 13-5: pwm time base interrupt timing, free-running mode 13.4.2 interrupts in single-shot mode when the pwm time base is in the single-shot mode (ptmod<1:0> = 01 ), an interrupt event is generated when a match with the ptper register occurs. the pwm time base register (ptmr) is reset to zero on the following input clock edge and the pten bit is cleared. the postscaler selection bits have no effect in this timer mode. 13.4.3 interrupts in continuous up/down count mode in the continuous up/down count mode (ptmod<1:0> = 10 ), an interrupt event is generated each time the value of the ptmr register becomes zero and the pwm time base begins to count upwards. the postscaler selection bits may be used in this timer mode to reduce the frequency of the interrupt events. figure 13-7 shows the interrupts in continuous up/ down count mode. q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 f osc /4 ptmr_int_req ffeh fffh 000h 001h 002h ptif bit note 1: pwm time base period register, ptper, is loaded with the value fffh for this example. qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc ptif bit ptmr ffeh fffh 001h 002h 1 a: prescaler = 1:1 b: prescaler = 1:4 ptmr ptmr_int_req q4 q4 1 000h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 121 figure 13-6: pwm time base interrupt timing, single-shot mode figure 13-7: pwm time base interrup ts, continuous up/down count mode q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 1 1 f osc /4 ptmr ffeh fffh 000h 000h 000h 1 ptif bit 2 note 1: interrupt flag bit, ptif, is sampled here (every q1). 2: pwm time base period register, ptper, is loaded with the value fffh for this example. qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc 1 1 ptmr ffeh fffh 000h 000h 1 2 a: prescaler = 1:1 b: prescaler = 1:4 ptmr_int_req q4 q4 ptif bit ptmr_int_req 000h q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 f osc /4 ptmr 002h 001h 000h 001h 002h note 1: interrupt flag bit, ptif, is sampled here (every q1). qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc qc 1 1 ptmr 002h 001h 001h 002h 1 ptdir bit 1 prescaler = 1:1 prescaler = 1:4 ptif bit ptmr_int_req ptdir bit q4 q4 ptif bit ptmr_int_req 1 1 1 1 000h
pic18f1230/1330 ds39758b-page 122 advance information ? 2006 microchip technology inc. 13.4.4 interrupts in double update mode this mode is available in continuous up/down count mode. in the double update mode (ptmod<1:0> = 11 ), an interrupt event is generated each time the ptmr register is equal to zero and each time the ptmr matches the ptper register. figure 13-8 shows the interrupts in continuous up/down count mode with double updates. the double update mode provides two additional functions to the user in center-aligned mode. 1. the control loop bandwidth is doubled because the pwm duty cycles can be updated twice per period. 2. asymmetrical center-aligned pwm waveforms can be generated, which are useful for minimizing output waveform distortion in certain motor control applications. figure 13-8: pwm time base interrupts, continuous up/down count mode with double updates note: do not change the ptmod bits while pten is active. it will yield unexpected results. to change the pwm timer mode of operation, first clear the pten bit, load ptmod bits with required data and then set pten. q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 1 1 osc1 ptmr 3fdh 3feh 3ffh 3feh 3fdh 1 case 1: ptmr counting upwards q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 q2 q1 q3 q4 1 1 osc1 ptmr 002h 001h 000h 001h 002h 1 case 2: ptmr counting downwards 2 note 1: interrupt flag bit, ptif, is sampled here (every q1). 2: pwm time base period register, ptper, is loaded with the value 3ffh for this example. 1 1 ptif bit ptmr_int_req ptif bit ptmr_int_req a: prescaler = 1:1 ptdir bit ptdir bit
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 123 13.5 pwm period the pwm period is defined by the ptper register pair (ptperl and ptperh). the pwm period has 12-bit resolution by combining 4 lsbs of ptperh and 8 bits of ptperl. ptper is a double-buffered register used to set the counting period for the pwm time base. the ptper buffer contents are loaded into the ptper register at the following times: ? free-running and single-shot modes: when the ptmr register is reset to zero after a match with the ptper register. ? continuous up/down count modes: when the ptmr register is zero. the value held in the ptper buffer is automatically loaded into the ptper register when the pwm time base is disabled (pten = 0 ). figure 13-9 and figure 13-10 indicate the times when the contents of the ptper buffer are loaded into the actual ptper register. the pwm period can be calculated from the following formulas: equation 13-1: pwm period for free-running mode equation 13-2: pwm period for continuous up/down count mode the pwm frequency is the inverse of period; or equation 13-3: pwm frequency the maximum resolution (in bits) for a given device oscillator and pwm frequency can be determined from the following formula: equation 13-4: pwm resolution the pwm resolutions and frequencies are shown for a selection of execution speeds and ptper values in table 13-2. the pwm frequencies in table 13-2 are calculated for edge-aligned pwm mode. for center- aligned mode, the pwm frequencies will be approximately one-half the values indicated in this table. table 13-2: example pwm frequencies and resolutions t pwm = (ptper + 1) x ptmrps f osc /4 t pwm = (2 x ptper) x ptmrps f osc 4 pwm frequency = 1 pwm period pwm frequency = 1/t pwm f osc mips ptper value pwm resolution pwm frequency 40 mhz 10 0fffh 14 bits 2.4 khz 40 mhz 10 07ffh 13 bits 4.9 khz 40 mhz 10 03ffh 12 bits 9.8 khz 40 mhz 10 01ffh 11 bits 19.5 khz 40 mhz 10 ffh 10 bits 39.0 khz 40 mhz 10 7fh 9 bits 78.1 khz 40 mhz 10 3fh 8 bits 156.2 khz 40 mhz 10 1fh 7 bits 312.5 khz 40 mhz 10 0fh 6 bits 625 khz 25 mhz 6.25 0fffh 14 bits 1.5 khz 25 mhz 6.25 03ffh 12 bits 6.1 khz 25 mhz 6.25 ffh 10 bits 24.4 khz 10 mhz 2.5 0fffh 14 bits 610 hz 10 mhz 2.5 03ffh 12 bits 2.4 khz 10 mhz 2.5 ffh 10 bits 9.8 khz 5 mhz 1.25 0fffh 14 bits 305 hz 5 mhz 1.25 03ffh 12 bits 1.2 khz 5 mhz 1.25 ffh 10 bits 4.9 khz 4 mhz 1 0fffh 14 bits 244 hz 4 mhz 1 03ffh 12 bits 976 hz 4 mhz 1 ffh 10 bits 3.9 khz note: for center-aligned operation, pwm frequencies will be approximately 1/2 the value indicated in the table. resolution = log(2) log f osc f pwm
pic18f1230/1330 ds39758b-page 124 advance information ? 2006 microchip technology inc. figure 13-9: pwm period buffer updates in free-running mode figure 13-10: pwm period buffer updates in continuous up/down count modes old ptper value = 004 new ptper value = 007 period value loaded from ptper buffer register new value written to ptper buffer 0 1 2 3 4 0 1 2 3 0 1 2 3 4 5 6 7 4 old ptper value = 004 new ptper value = 007 period value loaded from ptper buffer register new value written to ptper buffer 0 1 2 3 4 3 2 1 0 1 2 3 5 6 7 3 2 1 0 4 5 6 4
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 125 13.6 pwm duty cycle pwm duty cycle is defined by the pdcx (pdcxl and pdcxh) registers. there are a total of three pwm duty cycle registers for four pairs of pwm channels. the duty cycle registers have 14-bit resolution by combin- ing the six lsbs of pdcxh with the 8 bits of pdcxl. pdcx is a double-buffered register used to set the counting period for the pwm time base. 13.6.1 pwm duty cycle registers there are three 14-bit special function registers used to specify duty cycle values for the pwm module: ? pdc0 (pdc0l and pdc0h) ? pdc1 (pdc1l and pdc1h) ? pdc2 (pdc2l and pdc2h) the value in each duty cycle register determines the amount of time that the pwm output is in the active state. the upper 12 bits of pdcx hold the actual duty cycle value from ptmrh/l<11:0>, while the lower two bits control which internal q clock the duty cycle match will occur. this 2-bit value is decoded from the q clocks, as shown in figure 13-11, when the prescaler is 1:1 (ptckps<1:0> = 00 ). in edge-aligned mode, the pwm period starts at q1 and ends when the duty cycle register matches the ptmr register as follows. the duty cycle match is considered when the upper 12 bits of the pdcx are equal to the ptmr and the lower 2 bits are equal to q1, q2, q3 or q4, depending on the lower two bits of the pdcx (when the prescaler is 1:1 or ptckps<1:0> = 00 ) . each compare unit has logic that allows override of the pwm signals. this logic also ensures that the pwm signals will complement each other (with dead-time insertion) in complementary mode (see section 13.7 ?dead-time generators? ). figure 13-11: duty cycle comparison note: when the prescaler is not 1:1 (ptckps<1:0> ~ 00 ), the duty cycle match occurs at the q1 clock of the instruction cycle when the ptmr and pdcx match occurs. note: to get the correct pwm duty cycle, always multiply the calculated pwm duty cycle value by four before writing it to the pwm duty cycle registers. this is due to the two additional lsbs in the pwm duty cycle registers which are compared against the internal q clock for the pwm duty cycle match. ptmr<11:0> pdcx<13:0> comparator unused unused ptmrh<7:0> ptmrl<7:0> ptmrh<3:0> ptmrl<7:0> q clocks (1) pdcxh<7:0> pdcxl<7:0> pdcxh<5:0> pdcxl<7:0> <1:0> note 1: this value is decoded from the q clocks: 00 = duty cycle match occurs on q1 01 = duty cycle match occurs on q2 10 = duty cycle match occurs on q3 11 = duty cycle match occurs on q4
pic18f1230/1330 ds39758b-page 126 advance information ? 2006 microchip technology inc. 13.6.2 duty cycle register buffers the three pwm duty cycle registers are double- buffered to allow glitchless updates of the pwm outputs. for each duty cycle block, there is a duty cycle buffer register that is accessible by the user and a second duty cycle register that holds the actual compare value used in the present pwm period. in edge-aligned pwm output mode, a new duty cycle value will be updated whenever a ptmr match with the ptper register occurs and ptmr is reset, as shown in figure 13-12. also, the contents of the duty cycle buffers are automatically loaded into the duty cycle registers when the pwm time base is disabled (pten = 0 ). when the pwm time base is in the continuous up/ down count mode, new duty cycle values will be updated when the value of the ptmr register is zero and the pwm time base begins to count upwards. the contents of the duty cycle buffers are automatically loaded into the duty cycle registers when the pwm time base is disabled (pten = 0 ). figure 13-13 shows the timings when the duty cycle update occurs for the continuous up/down count mode. in this mode, up to one entire pwm period is available for calculating and loading the new pwm duty cycle before changes take effect. when the pwm time base is in the continuous up/ down count mode with double updates, new duty cycle values will be updated when the value of the ptmr register is zero and when the value of the ptmr register matches the value in the ptper register. the contents of the duty cycle buffers are automatically loaded into the duty cycle registers during both of the previously described conditions. figure 13-14 shows the duty cycle updates for continuous up/down count mode with double updates. in this mode, up to half of a pwm period is available for calculating and loading the new pwm duty cycle before changes take effect. 13.6.3 edge-aligned pwm edge-aligned pwm signals are produced by the module when the pwm time base is in the free-running mode or the single-shot mode. for edge-aligned pwm outputs, the output for a given pwm channel has a period specified by the value loaded in ptper and a duty cycle specified by the appropriate duty cycle register (see figure 13-12). the pwm output is driven active at the beginning of the period (ptmr = 0 ) and is driven inactive when the value in the duty cycle register matches ptmr. a new cycle is started when ptmr matches the ptper, as explained in the pwm period section. if the value in a particular duty cycle register is zero, then the output on the corresponding pwm pin will be inactive for the entire pwm period. in addition, the out- put on the pwm pin will be active for the entire pwm period if the value in the duty cycle register is greater than the value held in the ptper register. figure 13-12: edge-aligned pwm figure 13-13: duty cycle update time s in continuous up/down count mode period duty cycle 0 ptper ptmr value new duty cycle latched active at of period beginning pdcx pdcx (new) (old) ptmr value pwm output duty cycle value loaded from buffer register new value written to duty cycle buffer
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 127 figure 13-14: duty cycle update times in continuous up/down count mode with double updates 13.6.4 center-aligned pwm center-aligned pwm signals are produced by the module when the pwm time base is configured in a continuous up/down count mode (see figure 13-15). the pwm compare output is driven to the active state when the value of the duty cycle register matches the value of ptmr and the pwm time base is counting downwards (ptdir = 1 ). the pwm compare output will be driven to the inactive state when the pwm time base is counting upwards (ptdir = 0 ) and the value in the ptmr register matches the duty cycle value. if the value in a particular duty cycle register is zero, then the output on the corresponding pwm pin will be inactive for the entire pwm period. in addition, the output on the pwm pin will be active for the entire pwm period if the value in the duty cycle register is equal to or greater than the value in the ptper register. figure 13-15: start of center-aligned pwm ptmr value pwm output duty cycle value loaded from buffer register new values written to duty cycle buffer note: when the pwm is started in center- aligned mode, the pwm time base period register (ptper) is loaded into the pwm time base register (ptmr) and the ptmr is configured automatically to start down counting. this is done to ensure that all the pwm signals don?t start at the same time. 0 ptper ptmr value period period/2 duty cycle start of first pwm period period duty cycle
pic18f1230/1330 ds39758b-page 128 advance information ? 2006 microchip technology inc. 13.6.5 complementary pwm operation the complementary mode of pwm operation is useful to drive one or more power switches in half-bridge configuration, as shown in figure 13-16. this inverter topology is typical for a 3-phase induction motor, brushless dc motor or 3-phase uninterruptible power supply (ups) control applications. each upper/lower power switch pair is fed by a complementary pwm signal. dead time may be optionally inserted during device switching, where both outputs are inactive for a short period (see section 13.7 ?dead-time generators? ). in complementary mode, the duty cycle comparison units are assigned to the pwm outputs as follows: ? pdc0 register controls pwm1/pwm0 outputs ? pdc1 register controls pwm3/pwm2 outputs ? pdc2 register controls pwm5/pwm4 outputs pwm1/3/5 are the main pwms that are controlled by the pdcx registers and pwm0/2/4 are the complemented outputs. when using the pwms to control the half-bridge, the odd number pwms can be used to control the upper power switch and the even numbered pwms can be used for the lower switches. figure 13-16: typical load for complementary pwm outputs the complementary mode is selected for each pwm i/o pin pair by clearing the appropriate pmodx bit in the pwmcon0 register. the pwm i/o pins are set to complementary mode by default upon all kinds of device resets. +v pwm1 pwm0 pwm3 pwm2 pwm5 pwm4 3-phase load
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 129 13.7 dead-time generators in power inverter applications, where the pwms are used in complementary mode to control the upper and lower switches of a half-bridge, a dead-time insertion is highly recommended. the dead-time insertion keeps both outputs in inactive state for a brief time. this avoids any overlap in the switching during the state change of the power devices due to t on and t off characteristics. because the power output devices cannot switch instantaneously, some amount of time must be provided between the turn-off event of one pwm output in a complementary pair and the turn-on event of the other transistor. the pwm module allows dead time to be programmed. the following sections explain the dead-time block in detail. 13.7.1 dead-time insertion each complementary output pair for the pwm module has a 6-bit down counter used to produce the dead- time insertion. as shown in figure 13-17, each dead- time unit has a rising and falling edge detector connected to the duty cycle comparison output. the dead time is loaded into the timer on the detected pwm edge event. depending on whether the edge is rising or falling, one of the transitions on the complementary outputs is delayed until the timer counts down to zero. a timing diagram, indicating the dead-time insertion for one pair of pwm outputs, is shown in figure 13-18. figure 13-17: dead-time control unit bl ock diagram for one pwm output pair figure 13-18: dead-time insertion for complementary pwm even pwm signal to output control block odd pwm signal to output control block zero compare clock control and prescaler 6-bit down counter duty cycle compare input dead time prescale f osc dead time select bits dead-time register t d pdc1 compare output pwm1 pwm0 t d
pic18f1230/1330 ds39758b-page 130 advance information ? 2006 microchip technology inc. 13.7.2 dead-time ranges the amount of dead time provided by the dead-time unit is selected by specifying the input clock prescaler value and a 6-bit unsigned value defined in the dtcon register. four input clock prescaler selections have been provided to allow a suitable range of dead times based on the device operating frequency. f osc /2, f osc /4, f osc /8 and f osc /16 are the clock prescaler options available using the dtps1:dtps0 control bits in the dtcon register. after selecting an appropriate prescaler value, the dead time is adjusted by loading a 6-bit unsigned value into dtcon<5:0>. the dead-time unit prescaler is cleared on any of the following events: ? on a load of the down timer due to a duty cycle comparison edge event; ? on a write to the dtcon register; or ? on any device reset. 13.7.3 decrementing the dead-time counter the dead-time counter is clocked from any of the q clocks based on the following conditions. 1. the dead-time counter is clocked on q1 when: ? the dtps bits are set to any of the following dead-time prescaler settings: f osc /4, f osc /8, f osc /16 ? the pwm time base prescale bits (ptckps<1:0>) are set to any of the following prescale ratios: f osc /16, f osc /64, f osc /256 2. the dead-time counter is clocked by a pair of q clocks when the pwm time base prescale bits are set to 1:1 (ptckps<1:0> = 00 , f osc /4) and the dead-time counter is clocked by the f osc /2 (dtps<1:0> = 00 ). 3. the dead-time counter is clocked using every other q clock, depending on the two lsbs in the duty cycle registers: ? if the pwm duty cycle match occurs on q1 or q3, then the dead-time counter is clocked using every q1 and q3 ? if the pwm duty cycles match occurs on q2 or q4, then the dead-time counter is clocked using every q2 and q4 4. when the dtps<1:0> bits are set to any of the other dead-time prescaler settings (i.e., f osc /4, f osc /8 or f osc /16) and the pwm time base pres- caler is set to 1:1, the dead-time counter is clocked by the q clock corresponding to the q clocks on which the pwm duty cycle match occurs. register 13-5: dtcon: de ad-time control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 dtps1 dtps0 dt5 dt4 dt3 dt2 dt1 dt0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 dtps1:dtps0: dead-time unit a prescale select bits 11 = clock source for dead-time unit is f osc /16 10 = clock source for dead-time unit is f osc /8 01 = clock source for dead-time unit is f osc /4 00 = clock source for dead-time unit is f osc /2 bit 5-0 dt5:dt0: unsigned 6-bit dead-time value for dead-time unit bits
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 131 the actual dead time is calculated from the dtcon register as follows: dead time = dead-time value/(f osc /prescaler) table 13-3 shows example dead-time ranges as a function of the input clock prescaler selected and the device operating frequency. table 13-3: example dead-time ranges 13.7.4 dead-time distortion 13.8 independent pwm output independent pwm mode is used for driving the loads (as shown in figure 13-19) that drive one winding of a switched reluctance motor. a particular pwm output pair is configured in the independent output mode when the corresponding pmodx bit in the pwmcon0 register is set. no dead-time control is implemented between the pwm i/o pins when the module is operat- ing in the independent pwm mode and both i/o pins are allowed to be active simultaneously. this mode can also be used to drive stepper motors. 13.8.1 duty cycle assignment in the independent pwm mode in the independent pwm mode, each duty cycle gener- ator is connected to both pwm output pins in a given pwm output pair. the odd and the even pwm output pins are driven with a single pwm duty cycle generator. pwm1 and pwm0 are driven by the pwm channel which uses the pdc0 register to set the duty cycle, pwm3 and pwm2 with pdc1, and pwm5 and pwm4 with pdc2 (see figure 13-3 and register 13-3). f osc (mhz) mips prescaler selection dead-time min dead-time max 40 10 f osc /2 50 ns 3.2 s 40 10 f osc /4 100 ns 6.4 s 40 10 f osc /8 200 ns 12.8 s 40 10 f osc /16 400 ns 25.6 s 32 8 f osc /2 62.5 ns 4 s 32 8 f osc /4 125 ns 8 s 32 8 f osc /8 250 ns 16 s 32 8 f osc /16 500 ns 32 s 25 6.25 f osc /2 80 ns 5.12 s 25 6.25 f osc /4 160 ns 10.2 s 25 6.25 f osc /8 320 ns 20.5 s 25 6.25 f osc /16 640 ns 41 s 20 5 f osc /2 100 ns 6.4 s 20 5 f osc /4 200 ns 12.8 s 20 5 f osc /8 400 ns 25.6 s 20 5 f osc /16 800 ns 51.2 s 10 2.5 f osc /2 200 ns 12.8 s 10 2.5 f osc /4 400 ns 25.6 s 10 2.5 f osc /8 800 ns 51.2 s 10 2.5 f osc /16 1.6 s 102.4 s 51.25f osc /2 400 ns 25.6 s 51.25f osc /4 800 ns 51.2 s 51.25f osc /8 1.6 s 102.4 s 51.25f osc /16 3.2 s 204.8 s 41f osc /2 0.5 s32 s 41f osc /4 1 s64 s 41f osc /8 2 s128 s 41f osc /16 4 s256 s note 1: for small pwm duty cycles, the ratio of dead time to the active pwm time may become large. in this case, the inserted dead time will introduce distortion into waveforms produced by the pwm mod- ule. the user can ensure that dead-time distortion is minimized by keeping the pwm duty cycle at least three times larger than the dead time. a similar effect occurs for duty cycles at or near 100%. the maximum duty cycle used in the application should be chosen such that the minimum inactive time of the signal is at least three times larger than the dead time. if the dead time is greater or equal to the duty cycle of one of the pwm output pairs, then that pwm pair will be inactive for the whole period. 2: changing the dead-time values in dtcon when the pwm is enabled may result in an undesirable situation. disable the pwm (pten = 0 ) before changing the dead-time value.
pic18f1230/1330 ds39758b-page 132 advance information ? 2006 microchip technology inc. 13.8.2 pwm channel override pwm output may be manually overridden for each pwm channel by using the appropriate bits in the ovdcond and ovdcons registers. the user may select the following signal output options for each pwm output pin operating in the independent pwm mode: ? i/o pin outputs pwm signal ? i/o pin inactive ? i/o pin active refer to section 13.10 ?pwm output override? for details for all the override functions. figure 13-19: center connected load 13.9 single-pulse pwm operation the single-pulse pwm operation is available only in edge-aligned mode. in this mode, the pwm module will produce single-pulse output. single-pulse operation is configured when the ptmod1:ptmod0 bits are set to ? 01 ? in the ptcon0 register. this mode of operation is useful for driving certain types of ecms. in single-pulse mode, the pwm i/o pin(s) are driven to the active state when the pten bit is set. when the pwm timer match with duty cycle register occurs, the pwm i/o pin is driven to the inactive state. when the pwm timer match with the ptper register occurs, the ptmr register is cleared, all active pwm i/o pins are driven to the inactive state, the pten bit is cleared and an interrupt is generated if the corresponding interrupt bit is set. 13.10 pwm output override the pwm output override bits allow the user to manually drive the pwm i/o pins to specified logic states, independent of the duty cycle comparison units. the pwm override bits are useful when controlling various types of ecms, like a bldc motor. ovdcond and ovdcons registers are used to define the pwm override options. the ovdcond register contains six bits, povd5:povd0, that determine which pwm i/o pins will be overridden. the ovdcons register contains six bits, pout5:pout0, that determine the state of the pwm i/o pins when a particular output is overridden via the povd bits. the povd bits are active-low control bits. when the povd bits are set, the corresponding pout bit will have no effect on the pwm output. in other words, the pins corresponding to povd bits that are set will have the duty pwm cycle set by the pdcx registers. when one of the povd bits is cleared, the output on the corresponding pwm i/o pin will be determined by the state of the pout bit. when a pout bit is set, the pwm pin will be driven to its active state. when the pout bit is cleared, the pwm pin will be driven to its inactive state. 13.10.1 complementary output mode the even numbered pwm i/o pins have override restrictions when a pair of pwm i/o pins are operating in the complementary mode (pmodx = 0 ). in complementary mode, if the even numbered pin is driven active by clearing the corresponding povd bit and by setting the pout bits in the ovdcond and ovdcons registers, the output signal is forced to be the complement of the odd numbered i/o pin in the pair (see figure 13-2 for details). 13.10.2 override synchronization if the osync bit in the pwmcon1 register is set, all output overrides performed via the ovdcond and ovdcons registers will be synchronized to the pwm time base. synchronous output overrides will occur on the following conditions: ? when the pwm is in edge-aligned mode, synchronization occurs when ptmr is zero. ? when the pwm is in center-aligned mode, synchronization occurs when ptmr is zero and when the value of ptmr matches ptper. note: ptper and pdcx values are held as they are after the single-pulse output. to have another cycle of single pulse, only pten has to be enabled. +v pwm1 pwm0 load note 1: in the complementary mode, the even channel cannot be forced active by a fault or override event when the odd channel is active. the even channel is always the complement of the odd channel, with dead-time inserted, before the odd channel can be driven to its active state as shown in figure 13-20. 2: dead time inserted in the pwm channels even when they are in override mode.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 133 figure 13-20: override bits in complementary mode 1. even override bits have no effect in complementary mode. 2. odd override bit is activated which causes the even pwm to deactivate. 3. dead-time insertion. 4. odd pwm activated after the dead time. 5. odd override bit is deactivated which causes the odd pwm to deactivate. 6. dead-time insertion. 7. even pwm is activated after the dead time. pout0 pout1 pwm1 pwm0 assume: povd0 = 0 ; povd1 = 0 ; pmod0 = 0 6 5 4 3 2 7 1
pic18f1230/1330 ds39758b-page 134 advance information ? 2006 microchip technology inc. 13.10.3 output override examples figure 13-21 shows an example of a waveform that might be generated using the pwm output override feature. the figure shows a six-step commutation sequence for a bldc motor. the motor is driven through a 3-phase inverter as shown in figure 13-16. when the appropriate rotor position is detected, the pwm outputs are switched to the next commutation state in the sequence. in this example, the pwm outputs are driven to specific logic states. the ovdcond and ovdcons register values used to generate the signals in figure 13-21 are given in table 13-4. the pwm duty cycle registers may be used in conjunction with the ovdcond and ovdcons registers. the duty cycle registers control the average voltage across the load and the ovdcond and ovdcons registers control the commutation sequence. figure 13-22 shows the waveforms, while table 13-4 and table 13-5 show the ovdcond and ovdcons register values used to generate the signals. register 13-6: ovdcond: output override control register u-0 u-0 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 r/w-1 ? ? povd5 povd4 povd3 povd2 povd1 povd0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 povd5:povd0: pwm output override bits 1 = output on pwm i/o pin is controlled by the value in the duty cycle register and the pwm time base 0 = output on pwm i/o pin is controlled by the value in the corresponding poutx bit register 13-7: ovdcons: output state register u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? pout5 pout4 pout3 pout2 pout1 pout0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5-0 pout5:pout0: pwm manual output bits 1 = output on pwm i/o pin is active when the corresponding pwm output override bit is cleared 0 = output on pwm i/o pin is inactive when the corresponding pwm output override bit is cleared
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 135 figure 13-21: pwm output override example #1 table 13-4: pwm output override example #1 table 13-5: pwm output override example #2 figure 13-22: pwm output override example #2 13.11 pwm output and polarity control there are three device configuration bits associated with the pwm module that provide pwm output pin control defined in the config3l register. they are: ?hpol ?lpol ?pwmpin these three configuration bits work in conjunction with the three pwm enable bits (pwmen2:pwmen0) in the pwmcon0 register. the configuration bits and pwm enable bits ensure that the pwm pins are in the correct states after a device reset occurs. 13.11.1 output pin control the pwmen2:pwmen0 control bits enable each pwm output pin as required in the application. all pwm i/o pins are general purpose i/o. when a pair of pins is enabled for pwm output, the port and tris registers controlling the pins are disabled. refer to figure 13-23 for details. 13.11.2 output polarity control the polarity of the pwm i/o pins is set during device programming via the hpol and lpol configuration bits in the config3l register. the hpol configura- tion bit sets the output polarity for the high side pwm outputs: pwm1, pwm3 and pwm5. the polarity is active-high when hpol is cleared (= 0 ) and active-low when it is set (= 1 ). the lpol configuration bit sets the output polarity for the low side pwm outputs: pwm0, pwm2 and pwm4. as with hpol, they are active-high when lpol is cleared and active-low when set. all output signals generated by the pwm module are referenced to the polarity control bits, including those generated by fault inputs or manual override (see section 13.10 ?pwm output override? ). the default polarity configuration bits have the pwm i/o pins in active-high output polarity. state ovdcond (povd) ovdcons (pout) 1 00000000b 00100100b 2 00000000b 00100001b 3 00000000b 00001001b 4 00000000b 00011000b 5 00000000b 00010010b 6 00000000b 00000110b state ovdcond (povd) ovdcons (pout) 1 00000011b 00000000b 2 00110000b 00000000b 3 00111100b 00000000b 4 00001111b 00000000b pwm5 pwm4 pwm3 pwm2 pwm1 pwm0 12345 6 pwm5 pwm4 pwm3 pwm2 pwm1 pwm0 1 2 3 4
pic18f1230/1330 ds39758b-page 136 advance information ? 2006 microchip technology inc. figure 13-23: pwm i/o pin block diagram 13.11.3 pwm output pin reset states the pwmpin configuration bit determines the pwm output pins to be pwm output pins, or digital i/o pins, after the device comes out of reset. if the pwmpin configuration bit is unprogrammed (default), the pwmen2:pwmen0 control bits will be cleared on a device reset. consequently, all pwm outputs will be tri-stated and controlled by the corresponding port and tris registers. if the pwmpin configuration bit is programmed low, the pwmen2:pwmen0 control bits will be set to ? 100 ? on a device reset: all pwm pins will be enabled for pwm output and will have the output polarity defined by the hpol and lpol configuration bits. 13.12 pwm fault input there is one fault input associated with the pwm module. the main purpose of the input fault pin is to disable the pwm output signals and drive them into an inactive state. the action of the fault input is performed directly in hardware so that when a fault occurs, it can be managed quickly and the pwms outputs are put into an inactive state to save the power devices connected to the pwms. the pwm fault input is flta , which can come from i/o pins, the cpu or another module. the flta pin is an active-low input so it is easy to ?or? many sources to the same input. the fltconfig register (register 13-8) defines the settings of the flta input. 13.12.1 fault pin enable bit by setting the bit fltaen in the fltconfig register, the corresponding fault input is enabled. if fltaen bit is cleared, then the fault input has no effect on the pwm module. data bus wr port wr tris rd port data latch tris latch p v ss i/o pin q d q ck q d q ck q d en n v dd rd tris schmitt trigger ttl or 0 1 pwm pin enable pwm signal from module note: i/o pin has protection diodes to v dd and v ss . pwm polarity selection logic not shown for clarity. note: the inactive state of the pwm pins is dependent on the hpol and lpol con- figuration bit settings, which define the active and inactive state for pwm outputs.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 137 13.12.2 fault input mode the fltamod bit in the fltconfig register determines whether the pwm i/o pins are deactivated when they are overridden by a fault input. fltas bit in the fltconfig register gives the status of the fault a input. the fault input has two modes of operation: ? inactive mode (fltamod = 0 ) this is a catastrophic fault management mode. when the fault occurs in this mode, the pwm outputs are deactivated. the pwm pins will remain in inactivated mode until the fault is cleared (fault input is driven high) and the corresponding fault status bit has been cleared in software. the pwm outputs are enabled immediately at the beginning of the following pwm period, after fault status bit (fltas) is cleared. ? cycle-by-cycle mode (fltamod = 1 ) when the fault occurs in this mode, the pwm outputs are deactivated. the pwm outputs will remain in the defined fault states (all pwm outputs inactive) for as long as the fault pin is held low. after the fault pin is driven high, the pwm outputs will return to normal operation at the beginning of the following pwm period and the fltas bit is automatically cleared. 13.12.3 pwm outputs while in fault condition while in the fault state (i.e., f lta input is active), the pwm output signals are driven into their inactive states. 13.12.4 pwm outputs in debug mode the brfen bit in the fltconfig register controls the simulation of fault condition when a breakpoint is hit, while debugging the application using an in-circuit debugger (icd). setting the brfen bit to high enables the fault condition on breakpoint, thus driving the pwm outputs to inactive state. this is done to avoid any continuous keeping of status on the pwm pin, which may result in damage of the power devices connected to the pwm outputs. if brfen = 0 , the fault condition on breakpoint is disabled. note: it is highly recommended to enable the fault condition on breakpoint if a debugging tool is used while developing the firmware and the high-power circuitry is used. when the device is ready to program after debugging the firmware, the brfen bit can be disabled. register 13-8: fltconfig: fault configuration register r/w-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 brfen ? ? ? ? fltas fltamod fltaen bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 brfen: breakpoint fault enable bit 1 = enable fault condition on a breakpoint 0 = disable fault condition bit 6-3 unimplemented: read as ? 0 ? bit 2 fltas: fault a status bit 1 =flta is asserted; if fltamod = 0 , cleared by the user; if fltamod = 1 , cleared automatically at beginning of the new period when flta is deasserted 0 =no fault bit 1 fltamod: fault a mode bit 1 = cycle-by-cycle mode: pins are inactive for the remainder of the current pwm period or until flta is deasserted; fltas is cleared automatically 0 = inactive mode: pins are deactivated (catastrophic failure) until flta is deasserted and fltas is cleared by the user only bit 0 fltaen: fault a enable bit 1 = enable fault a 0 = disable fault a
pic18f1230/1330 ds39758b-page 138 advance information ? 2006 microchip technology inc. 13.13 pwm update lockout for a complex pwm application, the user may need to write up to four duty cycle registers and the pwm time base period register, ptper, at a given time. in some applications, it is important that all buffer registers be written before the new duty cycle and period values are loaded for use by the module. a pwm update lockout feature may optionally be enabled so the user may specify when new duty cycle buffer values are valid. the pwm update lockout feature is enabled by setting the control bit, udis, in the pwmcon1 register. this bit affects all duty cycle buffer registers and the pwm time base period register, ptper. to perform a pwm update lockout: 1. set the udis bit. 2. write all duty cycle registers and ptper, if applicable. 3. clear the udis bit to re-enable updates. 4. with this, when udis bit is cleared, the buffer values will be loaded to the actual registers. this makes a synchronous loading of the registers. 13.14 pwm special event trigger the pwm module has a special event trigger capability that allows a/d conversions to be synchronized to the pwm time base. the a/d sampling and conversion time may be programmed to occur at any point within the pwm period. the special event trigger allows the user to minimize the delay between the time when a/d conversion results are acquired and the time when the duty cycle value is updated. the pwm 16-bit special event trigger register, sevtcmp (high and low), and five control bits in the pwmcon1 register are used to control its operation. the ptmr value for which a special event trigger should occur is loaded into the sevtcmp register pair. sevtdir bit in pwmcon1 register specifies the counting phase when the pwm time base is in a continuous up/down count mode. if the sevtdir bit is cleared, the special event trigger will occur on the upward counting cycle of the pwm time base. if sevtdir is set, the special event trigger will occur on the downward count cycle of the pwm time base. the sevtdir bit only effects this operation when the pwm timer is in the continuous up/down count mode. 13.14.1 special event trigger enable the pwm module will always produce special event trigger pulses. this signal may optionally be used by the a/d module. refer to chapter 15.0 "10-bit analog-to-digital converter (a/d) module" for details. 13.14.2 special event trigger postscaler the pwm special event trigger has a postscaler that allows a 1:1 to 1:16 postscale ratio. the postscaler is configured by writing the sevops3:sevops0 control bits in the pwmcon1 register. the special event trigger output postscaler is cleared on any write to the sevtcmp register pair, or on any device reset. note: the special event trigger will take place only for non-zero values in the sevtcmp registers.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 139 table 13-6: registers associated with the power control pwm module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 ipr3 ? ? ?ptip ? ? ? ?43 pie3 ? ? ?ptie ? ? ? ?43 pir3 ? ? ?ptif ? ? ? ?43 ptcon0 ptops3 ptops2 ptops1 ptops0 ptckps1 ptckps0 ptmod1 ptmod0 43 ptcon1 pten ptdir ? ? ? ? ? ?43 ptmrl (1) pwm time base register (lower 8 bits) 43 ptmrh (1) ? ? ? ? pwm time base register (upper 4 bits) 43 ptperl (1) pwm time base period register (lower 8 bits) 43 ptperh (1) ? ? ? ? pwm time base period register (upper 4 bits) 43 sevtcmpl (1) pwm special event compare register (lower 8 bits) 43 sevtcmph (1) ? ? ? ? pwm special event compare register (upper 4 bits) 44 pwmcon0 ? pwmen2 (2) pwmen1 (2) pwmen0 (2) ? pmod2 pmod1 pmod0 44 pwmcon1 sevops3 sevops2 sevops1 sevops0 sevtdir ? udis osync 44 dtcon dtps1 dtps0 dt5 dt4 dt3 dt2 dt1 dt0 44 fltconfig brfen ? ? ? ? fltas fltamod fltaen 43 ovdcond ? ? povd5 povd4 povd3 povd2 povd1 povd0 44 ovdcons ? ? pout5 pout4 pout3 pout2 pout1 pout0 44 pdc0l (1) pwm duty cycle #0l register (lower 8 bits) 43 pdc0h (1) ? ? pwm duty cycle #0h register (upper 6 bits) 43 pdc1l (1) pwm duty cycle #1l register (lower 8 bits) 43 pdc1h (1) ? ? pwm duty cycle #1h register (upper 6 bits) 43 pdc2l (1) pwm duty cycle #2l register (lower 8 bits) 43 pdc2h (1) ? ? pwm duty cycle #2h register (upper 6 bits) 43 legend: - = unimplemented, u = unchanged. shaded cells are not used with the power control pwm. note 1: double-buffered register pairs. refer to text for explanation of how these registers are read and written to. 2: reset condition of pwmen bits depends on the pwmpin configuration bit.
pic18f1230/1330 ds39758b-page 140 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 141 14.0 enhanced universal synchronous asynchronous receiver transmitter (eusart) the enhanced universal synchronous asynchronous receiver transmitter (eusart) module is one of the two serial i/o modules. (generically, the usart is also known as a serial communications interface or sci.) the eusart can be configured as a full-duplex asynchronous system that can communicate with peripheral devices, such as crt terminals and personal computers. it can also be configured as a half- duplex synchronous system that can communicate with peripheral devices, such as a/d or d/a integrated circuits, serial eeproms, etc. the enhanced usart module implements additional features, including automatic baud rate detection and calibration, automatic wake-up on sync break reception and 12-bit break character transmit. these features make it ideally suited for use in local interconnect network bus (lin bus) systems. the eusart can be configured in the following modes: ? asynchronous (full-duplex) with: - auto-wake-up on character reception - auto-baud calibration - 12-bit break character transmission ? synchronous ? master (half-duplex) with selectable clock polarity ? synchronous ? slave (half-duplex) with selectable clock polarity the pins of the enhanced usart are multiplexed with porta. in order to configure ra2/tx/ck and ra3/rx/dt as an eusart: ? bit spen (rcsta<7>) must be set (= 1 ) ? bit trisa<3> must be set (= 1 ) ? bit trisa<2> must be set (= 1 ) the operation of the enhanced usart module is controlled through three registers: ? transmit status and control (txsta) ? receive status and control (rcsta) ? baud rate control (baudcon) these are detailed on the following pages in register 14-1, register 14-2 and register 14-3, respectively. note: the eusart control will automatically reconfigure the pin from input to output as needed.
pic18f1230/1330 ds39758b-page 142 advance information ? 2006 microchip technology inc. register 14-1: txsta: transmit status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-1 r/w-0 csrc tx9 txen (1) sync sendb brgh trmt tx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 csrc: clock source select bit asynchronous mode: don?t care. synchronous mode: 1 = master mode (clock generated internally from brg) 0 = slave mode (clock from external source) bit 6 tx9: 9-bit transmit enable bit 1 = selects 9-bit transmission 0 = selects 8-bit transmission bit 5 txen: transmit enable bit (1) 1 = transmit enabled 0 = transmit disabled bit 4 sync: eusart mode select bit 1 = synchronous mode 0 = asynchronous mode bit 3 sendb: send break character bit asynchronous mode: 1 = send sync break on next transmission (cleared by hardware upon completion) 0 = sync break transmission completed synchronous mode: don?t care. bit 2 brgh: high baud rate select bit asynchronous mode: 1 = high speed 0 = low speed synchronous mode: unused in this mode. bit 1 trmt: transmit shift register status bit 1 = tsr empty 0 = tsr full bit 0 tx9d: 9th bit of transmit data can be address/data bit or a parity bit. note 1: sren/cren overrides txen in sync mode.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 143 register 14-2: rcsta: receive status and control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r-0 r-0 r-x spen rx9 sren cren adden ferr oerr rx9d bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 spen: serial port enable bit 1 = serial port enabled (configures rx/dt and tx/ck pins as serial port pins) 0 = serial port disabled (held in reset) bit 6 rx9: 9-bit receive enable bit 1 = selects 9-bit reception 0 = selects 8-bit reception bit 5 sren: single receive enable bit asynchronous mode: don?t care. synchronous mode ? m aster: 1 = enables single receive 0 = disables single receive this bit is cleared after reception is complete. synchronous mode ? s lave: don?t care. bit 4 cren: continuous receive enable bit asynchronous mode: 1 = enables receiver 0 = disables receiver synchronous mode: 1 = enables continuous receive until enable bit cren is cleared (cren overrides sren) 0 = disables continuous receive bit 3 adden: address detect enable bit asynchronous mode 9-bit (rx9 = 1 ): 1 = enables address detection, enables interrupt and loads the receive buffer when rsr<8> is set 0 = disables address detection, all bytes are received and ninth bit can be used as parity bit asynchronous mode 9-bit (rx9 = 0 ): don?t care. bit 2 ferr: framing error bit 1 = framing error (can be updated by reading rcreg register and receiving next valid byte) 0 = no framing error bit 1 oerr: overrun error bit 1 = overrun error (can be cleared by clearing bit cren) 0 = no overrun error bit 0 rx9d: 9th bit of received data this can be address/data bit or a parity bit and must be calculated by user firmware.
pic18f1230/1330 ds39758b-page 144 advance information ? 2006 microchip technology inc. register 14-3: baudcon: ba ud rate control register r/w-0 r-1 u-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 abdovf rcidl ? sckp brg16 ? wue abden bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 abdovf : auto-baud acquisition rollover status bit 1 = a brg rollover has occurred during auto-baud rate detect mode (must be cleared in software) 0 = no brg rollover has occurred bit 6 rcidl : receive operation idle status bit 1 = receive operation is idle 0 = receive operation is active bit 5 unimplemented: read as ? 0 ? bit 4 sckp : synchronous clock polarity select bit asynchronous mode: unused in this mode. synchronous mode: 1 = idle state for clock (ck) is a high level 0 = idle state for clock (ck) is a low level bit 3 brg16: 16-bit baud rate register enable bit 1 = 16-bit baud rate generator ? spbrgh and spbrg 0 = 8-bit baud rate generator ? spbrg on ly (compatible mode), spbrgh value ignored bit 2 unimplemented: read as ? 0 ? bit 1 wue: wake-up enable bit asynchronous mode: 1 = eusart will continue to sample the rx pin ? interrupt generated on falling edge; bit cleared in hardware on following rising edge 0 = rx pin not monitored or rising edge detected synchronous mode: unused in this mode. bit 0 abden : auto-baud detect enable bit asynchronous mode: 1 = enable baud rate measurement on the next character. requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement disabled or completed synchronous mode: unused in this mode.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 145 14.1 baud rate generator (brg) the brg is a dedicated 8-bit or 16-bit generator that supports both the asynchronous and synchronous modes of the eusart. by default, the brg operates in 8-bit mode; setting the brg16 bit (baudcon<3>) selects 16-bit mode. the spbrgh:spbrg register pair controls the period of a free-running timer. in asynchronous mode, bits brgh (txsta<2>) and brg16 (baudcon<3>) also control the baud rate. in synchronous mode, brgh is ignored. table 14-1 shows the formula for computation of the baud rate for different eusart modes which only apply in master mode (internally generated clock). given the desired baud rate and f osc , the nearest integer value for the spbrgh:spbrg registers can be calculated using the formulas in table 14-1. from this, the error in baud rate can be determined. an example calculation is shown in example 14-1. typical baud rates and error values for the various asynchronous modes are shown in table 14-2. it may be advantageous to use the high baud rate (brgh = 1 ), or the 16-bit brg to reduce the baud rate error, or achieve a slow baud rate for a fast oscillator frequency. writing a new value to the spbrgh:spbrg registers causes the brg timer to be reset (or cleared). this ensures the brg does not wait for a timer overflow before outputting the new baud rate. 14.1.1 operation in power-managed modes the device clock is used to generate the desired baud rate. when one of the power-managed modes is entered, the new clock source may be operating at a different frequency. this may require an adjustment to the value in the spbrg register pair. 14.1.2 sampling the data on the rx pin is sampled three times by a majority detect circuit to determine if a high or a low level is present at the rx pin. table 14-1: baud rate formulas configuration bits brg/eusart mode baud rate formula sync brg16 brgh 000 8-bit/asynchronous f osc /[64 (n + 1)] 001 8-bit/asynchronous f osc /[16 (n + 1)] 010 16-bit/asynchronous 011 16-bit/asynchronous f osc /[4 (n + 1)] 10x 8-bit/synchronous 11x 16-bit/synchronous legend: x = don?t care, n = value of spbrgh:spbrg register pair
pic18f1230/1330 ds39758b-page 146 advance information ? 2006 microchip technology inc. example 14-1: calculating baud rate error table 14-2: registers associated with baud rate generator for a device with f osc of 16 mhz, desired baud rate of 9600, asynchronous mode, 8-bit brg: desired baud rate = f osc /(64 ([spbrgh:spbrg] + 1)) solving for spbrgh:spbrg: x=((f osc /desired baud rate)/64) ? 1 = ((16000000/9600)/64) ? 1 = [25.042] = 25 calculated baud rate = 16000000/(64 (25 + 1)) = 9615 error = (calculated baud rate ? desi red baud rate)/de sired baud rate = (9615 ? 9600)/9600 = 0.16% name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page txsta csrc tx9 txen sync sendb brgh trmt tx9d 42 rcsta spen rx9 sren cren adden ferr oerr rx9d 42 baudcon abdovf rcidl ? sckp brg16 ? wue abden 42 spbrgh eusart baud rate generator register high byte 42 spbrg eusart baud rate generator register low byte 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the brg.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 147 table 14-3: baud rates for asynchronous modes baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2 ? ? ? 1.221 1.73 255 1.202 0.16 129 1201 -0.16 103 2.4 2.441 1.73 255 2.404 0.16 129 2.404 0.16 64 2403 -0.16 51 9.6 9.615 0.16 64 9.766 1.73 31 9.766 1.73 15 9615 -0.16 12 19.2 19.531 1.73 31 19.531 1.73 15 19.531 1.73 7 ? ? ? 57.6 56.818 -1.36 10 62.500 8.51 4 52.083 -9.58 2 ? ? ? 115.2 125.000 8.51 4 104.167 -9.58 2 78.125 -32.18 1 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.16 207 300 -0.16 103 300 -0.16 51 1.2 1.202 0.16 51 1201 -0.16 25 1201 -0.16 12 2.4 2.404 0.16 25 2403 -0.16 12 ? ? ? 9.6 8.929 -6.99 6 ? ? ? ? ? ? 19.2 20.833 8.51 2 ? ? ? ? ? ? 57.6 62.500 8.51 0 ? ? ? ? ? ? 115.2 62.500 -45.75 0 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3???????????? 1.2???????????? 2.4 ? ? ? ? ? ? 2.441 1.73 255 2403 -0.16 207 9.6 9.766 1.73 255 9.615 0.16 129 9.615 0.16 64 9615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 0 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 ? ? ? ? ? ? 300 -0.16 207 1.2 1.202 0.16 207 1201 -0.16 103 1201 -0.16 51 2.4 2.404 0.16 103 2403 -0.16 51 2403 -0.16 25 9.6 9.615 0.16 25 9615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ?
pic18f1230/1330 ds39758b-page 148 advance information ? 2006 microchip technology inc. baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 8332 0.300 0.02 4165 0.300 0.02 2082 300 -0.04 1665 1.2 1.200 0.02 2082 1.200 -0.03 1041 1.200 -0.03 520 1201 -0.16 415 2.4 2.402 0.06 1040 2.399 -0.03 520 2.404 0.16 259 2403 -0.16 207 9.6 9.615 0.16 259 9.615 0.16 129 9.615 0.16 64 9615 -0.16 51 19.2 19.231 0.16 129 19.231 0.16 64 19.531 1.73 31 19230 -0.16 25 57.6 58.140 0.94 42 56.818 -1.36 21 56.818 -1.36 10 55555 3.55 8 115.2 113.636 -1.36 21 113.636 -1.36 10 125.000 8.51 4 ? ? ? baud rate (k) sync = 0 , brgh = 0 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.04 832 300 -0.16 415 300 -0.16 207 1.2 1.202 0.16 207 1201 -0.16 103 1201 -0.16 51 2.4 2.404 0.16 103 2403 -0.16 51 2403 -0.16 25 9.6 9.615 0.16 25 9615 -0.16 12 ? ? ? 19.2 19.231 0.16 12 ? ? ? ? ? ? 57.6 62.500 8.51 3 ? ? ? ? ? ? 115.2 125.000 8.51 1 ? ? ? ? ? ? baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 40.000 mhz f osc = 20.000 mhz f osc = 10.000 mhz f osc = 8.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.00 33332 0.300 0.00 16665 0.300 0.00 8332 300 -0.01 6665 1.2 1.200 0.00 8332 1.200 0.02 4165 1.200 0.02 2082 1200 -0.04 1665 2.4 2.400 0.02 4165 2.400 0.02 2082 2.402 0.06 1040 2400 -0.04 832 9.6 9.606 0.06 1040 9.596 -0.03 520 9.615 0.16 259 9615 -0.16 207 19.2 19.193 -0.03 520 19.231 0.16 259 19.231 0.16 129 19230 -0.16 103 57.6 57.803 0.35 172 57.471 -0.22 86 58.140 0.94 42 57142 0.79 34 115.2 114.943 -0.22 86 116.279 0.94 42 113.636 -1.36 21 117647 -2.12 16 baud rate (k) sync = 0 , brgh = 1 , brg16 = 1 or sync = 1 , brg16 = 1 f osc = 4.000 mhz f osc = 2.000 mhz f osc = 1.000 mhz actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) actual rate (k) % error spbrg value (decimal) 0.3 0.300 0.01 3332 300 -0.04 1665 300 -0.04 832 1.2 1.200 0.04 832 1201 -0.16 415 1201 -0.16 207 2.4 2.404 0.16 415 2403 -0.16 207 2403 -0.16 103 9.6 9.615 0.16 103 9615 -0.16 51 9615 -0.16 25 19.2 19.231 0.16 51 19230 -0.16 25 19230 -0.16 12 57.6 58.824 2.12 16 55555 3.55 8 ? ? ? 115.2 111.111 -3.55 8 ? ? ? ? ? ? table 14-3: baud rates for asynchronous modes (continued)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 149 14.1.3 auto-baud rate detect the enhanced usart module supports the automatic detection and calibration of baud rate. this feature is active only in asynchronous mode and while the wue bit is clear. the automatic baud rate measurement sequence (figure 14-1) begins whenever a start bit is received and the abden bit is set. the calculation is self-averaging. in the auto-baud rate detect (abd) mode, the clock to the brg is reversed. rather than the brg clocking the incoming rx signal, the rx signal is timing the brg. in abd mode, the internal baud rate generator is used as a counter to time the bit period of the incoming serial byte stream. once the abden bit is set, the state machine will clear the brg and look for a start bit. the auto-baud rate detect must receive a byte with the value 55h (ascii ?u?, which is also the lin bus sync character) in order to calculate the proper bit rate. the measurement is taken over both a low and a high bit time in order to minimize any effects caused by asymmetry of the incoming signal. after a start bit, the spbrg begins counting up, using the preselected clock source on the first rising edge of rx. after eight bits on the rx pin or the fifth rising edge, an accumulated value totalling the proper brg period is left in the spbrgh:spbrg register pair. once the 5th edge is seen (this should correspond to the stop bit), the abden bit is automatically cleared. if a rollover of the brg occurs (an overflow from ffffh to 0000h), the event is trapped by the abdovf status bit (baudcon<7>). it is set in hardware by brg rollovers and can be set or cleared by the user in software. abd mode remains active after rollover events and the abden bit remains set (figure 14-2). while calibrating the baud rate period, the brg registers are clocked at 1/8th the preconfigured clock rate. note that the brg clock will be configured by the brg16 and brgh bits. independent of the brg16 bit setting, both the spbrg and spbrgh will be used as a 16-bit counter. this allows the user to verify that no carry occurred for 8-bit modes by checking for 00h in the spbrgh register. refer to table 14-4 for counter clock rates to the brg. while the abd sequence takes place, the eusart state machine is held in idle. the rcif interrupt is set once the fifth rising edge on rx is detected. the value in the rcreg needs to be read to clear the rcif interrupt. the contents of rcreg should be discarded. table 14-4: brg counter clock rates 14.1.3.1 abd and eusart transmission since the brg clock is reversed during abd acquisition, the eusart transmitter cannot be used during abd. this means that whenever the abden bit is set, txreg cannot be written to. users should also ensure that abden does not become set during a transmit sequence. failing to do this may result in unpredictable eusart operation. note 1: if the wue bit is set with the abden bit, auto-baud rate detection will occur on the byte following the break character. 2: it is up to the user to determine that the incoming character baud rate is within the range of the selected brg clock source. some combinations of oscillator frequency and eusart baud rates are not possible due to bit error rates. overall system timing and communication baud rates must be taken into consideration when using the auto-baud rate detection feature. brg16 brgh brg counter clock 00 f osc /512 01 f osc /128 10 f osc /128 11 f osc /32 note: during the abd sequence, spbrg and spbrgh are both used as a 16-bit counter, independent of the brg16 setting.
pic18f1230/1330 ds39758b-page 150 advance information ? 2006 microchip technology inc. figure 14-1: automatic baud rate calculation figure 14-2: brg overflow sequence brg value rx pin abden bit rcif bit bit 0 bit 1 (interrupt) read rcreg brg clock start auto-cleared set by user xxxxh 0000h edge #1 bit 2 bit 3 edge #2 bit 4 bit 5 edge #3 bit 6 bit 7 edge #4 edge #5 001ch note: the abd sequence requires the eusart module to be configured in asynchronous mode and wue = 0 . spbrg xxxxh 1ch spbrgh xxxxh 00h stop bit start bit 0 xxxxh 0000h 0000h ffffh brg clock abden bit rx pin abdovf bit brg value
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 151 14.2 eusart asynchronous mode the asynchronous mode of operation is selected by clearing the sync bit (txsta<4>). in this mode, the eusart uses standard non-return-to-zero (nrz) format (one start bit, eight or nine data bits and one stop bit). the most common data format is 8 bits. an on-chip dedicated 8-bit/16-bit baud rate generator can be used to derive standard baud rate frequencies from the oscillator. the eusart transmits and receives the lsb first. the eusart?s transmitter and receiver are functionally independent but use the same data format and baud rate. the baud rate generator produces a clock, either x16 or x64 of the bit shift rate depending on the brgh and brg16 bits (txsta<2> and baudcon<3>). parity is not supported by the hardware but can be implemented in software and stored as the 9th data bit. when operating in asynchronous mode, the eusart module consists of the following important elements: ? baud rate generator ? sampling circuit ? asynchronous transmitter ? asynchronous receiver ? auto-wake-up on sync break character ? 12-bit break character transmit ? auto-baud rate detection 14.2.1 eusart asynchronous transmitter the eusart transmitter block diagram is shown in figure 14-3. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the stop bit has been transmitted from the previous load. as soon as the stop bit is transmitted, the tsr is loaded with new data from the txreg register (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg register is empty and the txif flag bit (pir1<4>) is set. this interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txie (pie1<4>). txif will be set regardless of the state of txie; it cannot be cleared in software. txif is also not cleared immediately upon loading txreg but becomes valid in the second instruction cycle following the load instruction. polling txif immediately following a load of txreg will return invalid results. while txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr register is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. to set up an asynchronous transmission: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set transmit bit tx9. can be used as address/data bit. 5. enable the transmission by setting bit txen which will also set bit txif. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. load data to the txreg register (starts transmission). 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 14-3: eusart transmit block diagram note 1: the tsr register is not mapped in data memory so it is not available to the user. 2: flag bit txif is set when enable bit txen is set. txif txie interrupt txen baud rate clk spbrg baud rate generator tx9d msb lsb data bus txreg register tsr register (8) 0 tx9 trmt spen tx pin pin buffer and control 8 ? ? ? spbrgh brg16
pic18f1230/1330 ds39758b-page 152 advance information ? 2006 microchip technology inc. figure 14-4: asynchronous transmission figure 14-5: asynchronous transmission (back to back) table 14-5: registers associated with asynchronous transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 rcsta spen rx9 sren cren adden ferr oerr rx9d 42 txreg eusart transmit register 42 txsta csrc tx9 txen sync sendb brgh trmt tx9d 42 baudcon abdovf rcidl ? sckp brg16 ? wue abden 42 spbrgh eusart baud rate generator register high byte 42 spbrg eusart baud rate generator register low byte 42 legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous transmission. word 1 word 1 transmit shift reg start bit bit 0 bit 1 bit 7/8 write to txreg brg output (shift clock) tx (pin) txif bit (transmit buffer reg. empty flag) trmt bit (transmit shift reg. empty flag) 1 t cy stop bit word 1 transmit shift reg. write to txreg brg output (shift clock) tx (pin) txif bit (interrupt reg. flag) trmt bit (transmit shift reg. empty flag) word 1 word 2 word 1 word 2 stop bit start bit transmit shift reg. word 1 word 2 bit 0 bit 1 bit 7/8 bit 0 note: this timing diagram shows two consecutive transmissions. 1 t cy 1 t cy start bit
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 153 14.2.2 eusart asynchronous receiver the receiver block diagram is shown in figure 14-6. the data is received on the rx pin and drives the data recovery block. the data recovery block is actually a high-speed shifter operating at x16 times the baud rate, whereas the main receive serial shifter operates at the bit rate or at f osc . this mode would typically be used in rs-232 systems. to set up an asynchronous reception: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing bit sync and setting bit spen. 3. if interrupts are desired, set enable bit rcie. 4. if 9-bit reception is desired, set bit rx9. 5. enable the reception by setting bit cren. 6. flag bit, rcif, will be set when reception is complete and an interrupt will be generated if enable bit, rcie, was set. 7. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 8. read the 8-bit received data by reading the rcreg register. 9. if any error occurred, clear the error by clearing enable bit cren. 10. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. 14.2.3 setting up 9-bit mode with address detect this mode would typically be used in rs-485 systems. to set up an asynchronous reception with address detect enable: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brgh and brg16 bits, as required, to achieve the desired baud rate. 2. enable the asynchronous serial port by clearing the sync bit and setting the spen bit. 3. if interrupts are required, set the rcen bit and select the desired priority level with the rcip bit. 4. set the rx9 bit to enable 9-bit reception. 5. set the adden bit to enable address detect. 6. enable reception by setting the cren bit. 7. the rcif bit will be set when reception is complete. the interrupt will be acknowledged if the rcie and gie bits are set. 8. read the rcsta register to determine if any error occurred during reception, as well as read bit 9 of data (if applicable). 9. read rcreg to determine if the device is being addressed. 10. if any error occurred, clear the cren bit. 11. if the device has been addressed, clear the adden bit to allow all received data into the receive buffer and interrupt the cpu. figure 14-6: eusart receiv e block diagram x64 baud rate clk baud rate generator rx pin buffer and control spen data recovery cren oerr ferr rsr register msb lsb rx9d rcreg register fifo interrupt rcif rcie data bus 8 64 16 or stop start (8) 7 1 0 rx9 ? ? ? spbrg spbrgh brg16 or 4
pic18f1230/1330 ds39758b-page 154 advance information ? 2006 microchip technology inc. figure 14-7: asynchronous reception table 14-6: registers associated with asynchronous reception 14.2.4 auto-wake-up on sync break character during sleep mode, all clocks to the eusart are suspended. because of this, the baud rate generator is inactive and a proper byte reception cannot be performed. the auto-wake-up feature allows the controller to wake-up due to activity on the rx/dt line while the eusart is operating in asynchronous mode. the auto-wake-up feature is enabled by setting the wue bit (baudcon<1>). once set, the typical receive sequence on rx/dt is disabled and the eusart remains in an idle state, monitoring for a wake-up event independent of the cpu mode. a wake-up event consists of a high-to-low transition on the rx/dt line. (this coincides with the start of a sync break or a wake-up signal character for the lin protocol.) following a wake-up event, the module generates an rcif interrupt. the interrupt is generated synchronously to the q clocks in normal operating modes (figure 14-8) and asynchronously if the device is in sleep mode (figure 14-9). the interrupt condition is cleared by reading the rcreg register. the wue bit is automatically cleared once a low-to- high transition is observed on the rx line following the wake-up event. at this point, the eusart module is in idle mode and returns to normal operation. this signals to the user that the sync break event is over. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 rcsta spen rx9 sren cren adden ferr oerr rx9d 42 rcreg eusart receive register 42 txsta csrc tx9 txen sync sendb brgh trmt tx9d 42 baudcon abdovf rcidl ? sckp brg16 ? wue abden 42 spbrgh eusart baud rate genera tor register high byte 42 spbrg eusart baud rate generator register low byte 42 legend: ? = unimplemented locations read as ? 0 ?. shaded cells are not used for asynchronous reception. start bit bit 7/8 bit 1 bit 0 bit 7/8 bit 0 stop bit start bit start bit bit 7/8 stop bit rx (pin) rcv buffer reg rcv shift reg read rcv buffer reg rcreg rcif (interrupt flag) oerr bit cren word 1 rcreg word 2 rcreg stop bit note: this timing diagram shows three words appearing on the rx input. the rcreg (receive buffer) is read after the third word causin g the oerr (overrun) bit to be set.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 155 14.2.4.1 special considerations using auto-wake-up since auto-wake-up functions by sensing rising edge transitions on rx/dt, information with any state changes before the stop bit may signal a false end-of- character and cause data or framing errors. to work properly, therefore, the initial characters in the transmission must be all ? 0 ?s. this can be 00h (8 bytes) for standard rs-232 devices or 000h (12 bits) for lin bus. oscillator start-up time must also be considered, especially in applications using oscillators with longer start-up intervals (i.e., xt or hs mode). the sync break (or wake-up signal) character must be of sufficient length and be followed by a sufficient interval to allow enough time for the selected oscillator to start and provide proper initialization of the eusart. 14.2.4.2 special considerations using the wue bit the timing of wue and rcif events may cause some confusion when it comes to determining the validity of received data. as noted, setting the wue bit places the eusart in an idle mode. the wake-up event causes a receive interrupt by setting the rcif bit. the wue bit is cleared after this when a rising edge is seen on rx/dt. the interrupt condition is then cleared by reading the rcreg register. ordinarily, the data in rcreg will be dummy data and should be discarded. the fact that the wue bit has been cleared (or is still set) and the rcif flag is set should not be used as an indicator of the integrity of the data in rcreg. users should consider implementing a parallel method in firmware to verify received data integrity. to assure that no actual data is lost, check the rcidl bit to verify that a receive operation is not in process. if a receive operation is not occurring, the wue bit may then be set just prior to entering the sleep mode. figure 14-8: auto-wake-up bit (wue) timings during normal operation figure 14-9: auto-wake-up bit (wue) timings during sleep q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (1) rx/dt line rcif note 1: the eusart remains in idle while the wue bit is set. bit set by user cleared due to user read of rcreg auto-cleared q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 osc1 wue bit (2) rx/dt line rcif cleared due to user read of rcreg sleep command executed note 1: if the wake-up event requires long oscillator warm-up time, the auto-clear of the wue bit can occur before the oscillator is re ady. this sequence should not depend on the presence of q clocks. 2: the eusart remains in idle while the wue bit is set. sleep ends note 1 auto-cleared bit set by user
pic18f1230/1330 ds39758b-page 156 advance information ? 2006 microchip technology inc. 14.2.5 break character sequence the eusart module has the capability of sending the special break character sequences that are required by the lin bus standard. the break character transmit consists of a start bit, followed by twelve ? 0 ? bits and a stop bit. the frame break character is sent whenever the sendb and txen bits (txsta<3> and txsta<5>) are set while the transmit shift register is loaded with data. note that the value of data written to txreg will be ignored and all ? 0 ?s will be transmitted. the sendb bit is automatically reset by hardware after the corresponding stop bit is sent. this allows the user to preload the transmit fifo with the next transmit byte following the break character (typically, the sync character in the lin specification). note that the data value written to the txreg for the break character is ignored. the write simply serves the purpose of initiating the proper sequence. the trmt bit indicates when the transmit operation is active or idle, just as it does during normal transmission. see figure 14-10 for the timing of the break character sequence. 14.2.5.1 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. this sequence is typical of a lin bus master. 1. configure the eusart for the desired mode. 2. set the txen and sendb bits to set up the break character. 3. load the txreg with a dummy character to initiate transmission (the value is ignored). 4. write ?55h? to txreg to load the sync character into the transmit fifo buffer. 5. after the break has been sent, the sendb bit is reset by hardware. the sync character now transmits in the preconfigured mode. when the txreg becomes empty, as indicated by the txif, the next data byte can be written to txreg. 14.2.6 receiving a break character the enhanced usart module can receive a break character in two ways. the first method forces configuration of the baud rate at a frequency of 9/13 the typical speed. this allows for the stop bit transition to be at the correct sampling location (13 bits for break versus start bit and 8 data bits for typical data). the second method uses the auto-wake-up feature described in section 14.2.4 ?auto-wake-up on sync break character? . by enabling this feature, the eusart will sample the next two transitions on rx/dt, cause an rcif interrupt and receive the next data byte followed by another interrupt. note that following a break character, the user will typically want to enable the auto-baud rate detect feature. for both methods, the user can set the abden bit once the txif interrupt is observed. figure 14-10: send break character sequence write to txreg brg output (shift clock) start bit bit 0 bit 1 bit 11 stop bit break txif bit (transmit buffer reg. empty flag) tx (pin) trmt bit (transmit shift reg. empty flag) sendb (transmit shift reg. empty flag) sendb sampled here auto-cleared dummy write
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 157 14.3 eusart synchronous master mode the synchronous master mode is entered by setting the csrc bit (txsta<7>). in this mode, the data is transmitted in a half-duplex manner (i.e., transmission and reception do not occur at the same time). when transmitting data, the reception is inhibited and vice versa. synchronous mode is entered by setting bit sync (txsta<4>). in addition, enable bit spen (rcsta<7>) is set in order to configure the tx and rx pins to ck (clock) and dt (data) lines, respectively. the master mode indicates that the processor transmits the master clock on the ck line. clock polarity is selected with the sckp bit (baudcon<4>). setting sckp sets the idle state on ck as high, while clearing the bit sets the idle state as low. this option is provided to support microwire devices with this module. 14.3.1 eusart synchronous master transmission the eusart transmitter block diagram is shown in figure 14-3. the heart of the transmitter is the transmit (serial) shift register (tsr). the shift register obtains its data from the read/write transmit buffer register, txreg. the txreg register is loaded with data in software. the tsr register is not loaded until the last bit has been transmitted from the previous load. as soon as the last bit is transmitted, the tsr is loaded with new data from the txreg (if available). once the txreg register transfers the data to the tsr register (occurs in one t cy ), the txreg is empty and the txif flag bit (pir1<4>) is set. the interrupt can be enabled or disabled by setting or clearing the interrupt enable bit, txie (pie1<4>). txif is set regardless of the state of enable bit txie; it cannot be cleared in software. it will reset only when new data is loaded into the txreg register. while flag bit txif indicates the status of the txreg register, another bit, trmt (txsta<1>), shows the status of the tsr register. trmt is a read-only bit which is set when the tsr is empty. no interrupt logic is tied to this bit so the user has to poll this bit in order to determine if the tsr register is empty. the tsr is not mapped in data memory so it is not available to the user. to set up a synchronous master transmission: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 14-11: synchronous transmission bit 0 bit 1 bit 7 word 1 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 bit 2 bit 0 bit 1 bit 7 ra3/rx/dt ra2/tx/ck pin write to txreg reg txif bit (interrupt flag) txen bit ? 1 ? ? 1 ? word 2 trmt bit note: sync master mode, spbrg = 0 , continuous transmission of two 8-bit words. ra2/tx/ck pin (sckp = 0 ) (sckp = 1 ) write word 2 write word 1
pic18f1230/1330 ds39758b-page 158 advance information ? 2006 microchip technology inc. figure 14-12: synchronous transmis sion (through txen) table 14-7: registers associated with synchronous master transmission ra3/rx/dt pin ra2/tx/ck pin write to txreg reg txif bit trmt bit bit 0 bit 1 bit 2 bit 6 bit 7 txen bit name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 rcsta spen rx9 sren cren adden ferr oerr rx9d 42 txreg eusart transmit register 42 txsta csrc tx9 txen sync sendb brgh trmt tx9d 42 baudcon abdovf rcidl ?sckpbrg16 ? wue abden 42 spbrgh eusart baud rate generator register high byte 42 spbrg eusart baud rate generator register low byte 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master transmission.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 159 14.3.2 eusart synchronous master reception once synchronous mode is selected, reception is enabled by setting either the single receive enable bit, sren (rcsta<5>), or the continuous receive enable bit, cren (rcsta<4>). data is sampled on the rx pin on the falling edge of the clock. if enable bit sren is set, only a single word is received. if enable bit cren is set, the reception is continuous until cren is cleared. if both bits are set, then cren takes precedence. to set up a synchronous master reception: 1. initialize the spbrgh:spbrg registers for the appropriate baud rate. set or clear the brg16 bit, as required, to achieve the desired baud rate. 2. enable the synchronous master serial port by setting bits sync, spen and csrc. 3. ensure bits cren and sren are clear. 4. if interrupts are desired, set enable bit rcie. 5. if 9-bit reception is desired, set bit rx9. 6. if a single reception is required, set bit sren. for continuous reception, set bit cren. 7. interrupt flag bit, rcif, will be set when reception is complete and an interrupt will be generated if the enable bit, rcie, was set. 8. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 9. read the 8-bit received data by reading the rcreg register. 10. if any error occurred, clear the error by clearing bit cren. 11. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. figure 14-13: synchronous reception (master mode, sren) table 14-8: registers associated with synchronous master reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 rcsta spen rx9 sren cren adden ferr oerr rx9d 42 rcreg eusart receive register 42 txsta csrc tx9 txen sync sendb brgh trmt tx9d 42 baudcon abdovf rcidl ? sckp brg16 ? wue abden 42 spbrgh eusart baud rate generator register high byte 42 spbrg eusart baud rate generator register low byte 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous master reception. cren bit ra3/rx/dt ra2/tx/ck pin write to bit sren sren bit rcif bit (interrupt) read rxreg q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q2 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 q1 q2 q3 q4 ? 0 ? bit 0 bit 1 bit 2 bit 3 bit 4 bit 5 bit 6 bit 7 ? 0 ? q1 q2 q3 q4 note: timing diagram demonstrates sync master mode with bit sren = 1 and bit brgh = 0 . ra2/tx/ck pin pin (sckp = 0 ) (sckp = 1 )
pic18f1230/1330 ds39758b-page 160 advance information ? 2006 microchip technology inc. 14.4 eusart synchronous slave mode synchronous slave mode is entered by clearing bit, csrc (txsta<7>). this mode differs from the synchronous master mode in that the shift clock is supplied externally at the ck pin (instead of being supplied internally in master mode). this allows the device to transfer or receive data while in any low-power mode. 14.4.1 eusart synchronous slave transmission the operation of the synchronous master and slave modes are identical, except in the case of the sleep mode. if two words are written to the txreg and then the sleep instruction is executed, the following will occur: a) the first word will immediately transfer to the tsr register and transmit. b) the second word will remain in the txreg register. c) flag bit, txif, will not be set. d) when the first word has been shifted out of tsr, the txreg register will transfer the second word to the tsr and flag bit, txif, will now be set. e) if enable bit, txie, is set, the interrupt will wake the chip from sleep. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave transmission: 1. enable the synchronous slave serial port by setting bits sync and spen and clearing bit csrc. 2. clear bits cren and sren. 3. if interrupts are desired, set enable bit txie. 4. if 9-bit transmission is desired, set bit tx9. 5. enable the transmission by setting enable bit txen. 6. if 9-bit transmission is selected, the ninth bit should be loaded in bit tx9d. 7. start transmission by loading data to the txreg register. 8. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. table 14-9: registers associated with synchronous slave transmission name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 rcsta spen rx9 sren cren adden ferr oerr rx9d 42 txreg eusart transmit register 42 txsta csrc tx9 txen sync sendb brgh trmt tx9d 42 baudcon abdovf rcidl ? sckp brg16 ? wue abden 42 spbrgh eusart baud rate generator register high byte 42 spbrg eusart baud rate generator register low byte 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave transmission.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 161 14.4.2 eusart synchronous slave reception the operation of the synchronous master and slave modes is identical, except in the case of sleep, or any idle mode and bit sren, which is a ?don?t care? in slave mode. if receive is enabled by setting the cren bit prior to entering sleep or any idle mode, then a word may be received while in this low-power mode. once the word is received, the rsr register will transfer the data to the rcreg register; if the rcie enable bit is set, the interrupt generated will wake the chip from the low- power mode. if the global interrupt is enabled, the program will branch to the interrupt vector. to set up a synchronous slave reception: 1. enable the synchronous master serial port by setting bits sync and spen and clearing bit csrc. 2. if interrupts are desired, set enable bit rcie. 3. if 9-bit reception is desired, set bit rx9. 4. to enable reception, set enable bit cren. 5. flag bit, rcif, will be set when reception is complete. an interrupt will be generated if enable bit, rcie, was set. 6. read the rcsta register to get the 9th bit (if enabled) and determine if any error occurred during reception. 7. read the 8-bit received data by reading the rcreg register. 8. if any error occurred, clear the error by clearing bit cren. 9. if using interrupts, ensure that the gie and peie bits in the intcon register (intcon<7:6>) are set. table 14-10: registers associated with synchronous slave reception name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 rcsta spen rx9 sren cren adden ferr oerr rx9d 42 rcreg eusart receive register 42 txsta csrc tx9 txen sync sendb brgh trmt tx9d 42 baudcon abdovf rcidl ?sckpbrg16 ? wue abden 42 spbrgh eusart baud rate generator register high byte 42 spbrg eusart baud rate generator register low byte 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for synchronous slave reception.
pic18f1230/1330 ds39758b-page 162 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 163 15.0 10-bit analog-to-digital converter (a/d) module the analog-to-digital (a/d) converter module has 4 inputs for the 18/20/28-pin devices. this module allows conversion of an analog input signal to a corresponding 10-bit digital number in pic18f1230/ 1330 devices. the module has five registers: ? a/d result register high byte (adresh) ? a/d result register low byte (adresl) ? a/d control register 0 (adcon0) ? a/d control register 1 (adcon1) ? a/d control register 2 (adcon2) the adcon0 register, shown in register 15-1, controls the operation of the a/d module. the adcon1 register, shown in register 15-2, configures the functions of the port pins. the adcon2 register, shown in register 15-3, configures the a/d clock source, programmed acquisition time and justification. register 15-1: adcon0: a/d control register 0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 sevten ? ? ? chs1 chs0 go/done adon bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 sevten: special event trigger enable bit 1 = special event trigger from power control pwm module is enabled 0 = special event trigger from power control pwm module is disabled (default) bit 6-4 unimplemented: read as ? 0 ? bit 3-2 chs1:chs0: analog channel select bits 00 = channel 0 (an0) 01 = channel 1 (an1) 10 = channel 2 (an2) 11 = channel 3 (an3) bit 1 go/done : a/d conversion status bit when adon = 1 : 1 = a/d conversion in progress 0 = a/d idle bit 0 adon: a/d on bit 1 = a/d converter module is enabled 0 = a/d converter module is disabled
pic18f1230/1330 ds39758b-page 164 advance information ? 2006 microchip technology inc. register 15-2: adcon1: a/d control register 1 u-0 u-0 u-0 r/w-0 r/w-0 (1,2) r/w (1) r/w (1) r/w (1) ? ? ? vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-5 unimplemented: read as ? 0 ? bit 4 vcfg0: voltage reference configuration bit (v ref + source) 1 = positive reference for the a/d is v ref + 0 = positive reference for the a/d is av dd bit 3 pcfg3: a/d port configuration bit for ra6/an3 (1,2) 1 = port is configured as an3 0 = port is configured as ra6 bit 2 pcfg2: a/d port configuration bit for ra4/an2 (1) 1 = port is configured as an2 0 = port is configured as ra4 bit 1 pcfg1: a/d port configuration bit for ra1/an1 (1) 1 = port is configured as an1 0 = port is configured as ra1 bit 0 pcfg0: a/d port configuration bit for ra0/an0 (1) 1 = port is configured as an0 0 = port is configured as ra0 note 1: these bits reset to ? 1 ? to configure the port as an analog input after reset. 2: this bit is unused and reads as ? 0 ? if pin is not configured for use as ra6
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 165 register 15-3: adcon2: a/d control register 2 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 adfm: a/d result format select bit 1 = right justified 0 = left justified bit 6 unimplemented: read as ? 0 ? bit 5-3 acqt2:acqt0: a/d acquisition time select bits 111 = 20 t ad 110 = 16 t ad 101 = 12 t ad 100 = 8 t ad 011 = 6 t ad 010 = 4 t ad 001 = 2 t ad 000 = 0 t ad (1) bit 2-0 adcs2:adcs0: a/d conversion clock select bits 111 = f rc (clock derived from a/d rc oscillator) (1) 110 = f osc /64 101 = f osc /16 100 = f osc /4 011 = f rc (clock derived from a/d rc oscillator) (1) 010 = f osc /32 001 = f osc /8 000 = f osc /2 note 1: if the a/d f rc clock source is selected, a delay of one t cy (instruction cycle) is added before the a/d clock starts. this allows the sleep instruction to be executed before starting a conversion.
pic18f1230/1330 ds39758b-page 166 advance information ? 2006 microchip technology inc. the analog reference voltage is software selectable to the device?s positive supply voltage (v dd ), or the voltage level on the ra4/t0cki/an2/v ref + pin. the a/d converter has a unique feature of being able to operate while the device is in sleep mode. to operate in sleep, the a/d conversion clock must be derived from the a/d converter?s internal rc oscillator. the output of the sample and hold is the input into the converter, which generates the result via successive approximation. a device reset forces all registers to their reset state. this forces the a/d module to be turned off and any conversion in progress is aborted. each port pin associated with the a/d converter can be configured as an analog input or as a digital i/o. the adresh and adresl registers contain the result of the a/d conversion. when the a/d conversion is complete, the result is loaded into the adresh:adresl register pair, the go/done bit (adcon0 register) is cleared and a/d interrupt flag bit, adif, is set. the block diagram of the a/d module is shown in figure 15-1. figure 15-1: a/d block diagram (input voltage) v ain v ref + reference voltage av dd vcfg0 chs1:chs0 an3 an2 an1 an0 0011 0010 0001 0000 10-bit converter av ss a/d 1 0
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 167 the value in the adresh:adresl registers is not modified for a power-on reset. the adresh:adresl registers will contain unknown data after a power-on reset. after the a/d module has been configured as desired, the selected channel must be acquired before the conversion is started. the analog input channels must have their corresponding tris bits selected as inputs. to determine acquisition time, see section 15.2 ?a/d acquisition requirements? . after this acquisition time has elapsed, the a/d conversion can be started. an acquisition time can be programmed to occur between setting the go/done bit and the actual start of the conversion. the following steps should be followed to perform an a/d conversion: 1. configure the a/d module: ? configure analog pins, voltage reference and digital i/o (adcon1) ? select a/d input channel (adcon0) ? select a/d acquisition time (adcon2) ? select a/d conversion clock (adcon2) ? turn on a/d module (adcon0) 2. configure a/d interrupt (if desired): ? clear adif bit ? set adie bit ? set gie bit 3. wait the required acquisition time (if required). 4. start conversion: ? set go/done bit (adcon0 register) 5. wait for a/d conversion to complete, by either: ? polling for the go/done bit to be cleared or ? waiting for the a/d interrupt 6. read a/d result registers (adresh:adresl); clear bit adif, if required. 7. for next conversion, go to step 1 or step 2, as required. the a/d conversion time per bit is defined as t ad . a minimum wait of 2 t ad is required before the next acquisition starts. figure 15-2: a/d transfer function figure 15-3: analog input model digital code output 3feh 003h 002h 001h 000h 0.5 lsb 1 lsb 1.5 lsb 2 lsb 2.5 lsb 1022 lsb 1022.5 lsb 3 lsb analog input voltage 3ffh 1023 lsb 1023.5 lsb v ain c pin rs anx 5 pf v t = 0.6v v t = 0.6v i leakage r ic 1k sampling switch ss r ss c hold = 25 pf v ss v dd 100 na legend: c pin v t i leakage r ic ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch = sample/hold capacitance (from dac) various junctions = sampling switch resistance r ss v dd 6v sampling switch (k ) 5v 4v 3v 2v 1234
pic18f1230/1330 ds39758b-page 168 advance information ? 2006 microchip technology inc. 15.1 triggering a/d conversions the a/d conversion can be triggered by setting the go/ done bit. this bit can either be set manually by the programmer or by setting the sevten bit of adcon0. when the sevten bit is set, the special event trigger from the power control pwm module triggers the a/d conversion. for more information, see section 13.14 ?pwm special event trigger? . 15.2 a/d acquisition requirements for the a/d converter to meet its specified accuracy, the charge holding capacitor (c hold ) must be allowed to fully charge to the input channel voltage level. the analog input model is shown in figure 15-3. the source impedance (r s ) and the internal sampling switch (r ss ) impedance directly affect the time required to charge the capacitor c hold . the sampling switch (r ss ) impedance varies over the device voltage (v dd ). the source impedance affects the offset voltage at the analog input (due to pin leakage current). the maximum recommended impedance for analog sources is 2.5 k . after the analog input channel is selected (changed), the channel must be sampled for at least the minimum acquisition time before starting a conversion. to calculate the minimum acquisition time, equation 15-1 may be used. this equation assumes that 1/2 lsb error is used (1024 steps for the a/d). the 1/2 lsb error is the maximum error allowed for the a/d to meet its specified resolution. example 15-3 shows the calculation of the minimum required acquisition time, t acq . this calculation is based on the following application system assumptions: c hold =25 pf rs = 2.5 k conversion error 1/2 lsb v dd =5v r ss = 2 k temperature = 85 c (system max.) equation 15-1: acquisition time equation 15-2: a/d minimum charging time equation 15-3: calculating the minimum required acquisition time note: when the conversion is started, the holding capacitor is disconnected from the input pin. t acq = amplifier settling time + holding capacitor charging time + temperature coefficient =t amp + t c + t coff v hold = (v ref ? (v ref /2048)) ? (1 ? e (-t c /c hold (r ic + r ss + r s )) ) or t c = -(c hold )(r ic + r ss + r s ) ln(1/2048) t acq =t amp + t c + t coff t amp =0.2 s t coff = (temp ? 25 c)(0.02 s/ c) (85 c ? 25 c)(0.02 s/ c) 1.2 s temperature coefficient is only required for temperatures > 25 c. below 25 c, t coff = 0 ms. t c = -(c hold )(r ic + r ss + r s ) ln(1/2047) -(25 pf) (1 k + 2 k + 2.5 k ) ln(0.0004883) 1.05 s t acq =0.2 s + 1 s + 1.2 s 2.4 s
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 169 15.3 selecting and configuring acquisition time the adcon2 register allows the user to select an acquisition time that occurs each time the go/done bit is set. it also gives users the option to use an automatically determined acquisition time. acquisition time may be set with the acqt2:acqt0 bits (adcon2<5:3>), which provide a range of 2 to 20 t ad . when the go/done bit is set, the a/d module continues to sample the input for the selected acquisition time, then automatically begins a conversion. since the acquisition time is programmed, there may be no need to wait for an acquisition time between selecting a channel and setting the go/done bit. manual acquisition is selected when acqt2:acqt0 = 000 . when the go/done bit is set, sampling is stopped and a conversion begins. the user is responsible for ensuring the required acquisition time has passed between selecting the desired input channel and setting the go/done bit. this option is also the default reset state of the acqt2:acqt0 bits and is compatible with devices that do not offer programmable acquisition times. in either case, when the conversion is completed, the go/done bit is cleared, the adif flag is set and the a/d begins sampling the currently selected channel again. if an acquisition time is programmed, there is nothing to indicate if the acquisition time has ended or if the conversion has begun. 15.4 selecting the a/d conversion clock the a/d conversion time per bit is defined as t ad . the a/d conversion requires 11 t ad per 10-bit conversion. the source of the a/d conversion clock is software selectable. there are seven possible options for t ad : ?2 t osc ?4 t osc ?8 t osc ?16 t osc ?32 t osc ?64 t osc ? internal rc oscillator for correct a/d conversions, the a/d conversion clock (t ad ) must be as short as possible, but greater than the minimum t ad (see parameter 130 for more information). table 15-1 shows the resultant t ad times derived from the device operating frequencies and the a/d clock source selected. table 15-1: t ad vs. device operating frequencies ad clock source (t ad ) maximum device frequency operation adcs2:adcs0 pic18f1230/1330 pic18lf1230/1330 (4) 2 t osc 000 2.86 mhz 1.43 khz 4 t osc 100 5.71 mhz 2.86 mhz 8 t osc 001 11.43 mhz 5.72 mhz 16 t osc 101 22.86 mhz 11.43 mhz 32 t osc 010 40.0 mhz 22.86 mhz 64 t osc 110 40.0 mhz 22.86 mhz rc (3) x11 1.00 mhz (1) 1.00 mhz (2) note 1: the rc source has a typical t ad time of 1.2 s. 2: the rc source has a typical t ad time of 2.5 s. 3: for device frequencies above 1 mhz, the device must be in sleep for the entire conversion or the a/d accuracy may be out of specification. 4: low-power (pic18lf1230/1330) devices only.
pic18f1230/1330 ds39758b-page 170 advance information ? 2006 microchip technology inc. 15.5 operation in power-managed modes the selection of the automatic acquisition time and a/d conversion clock is determined in part by the clock source and frequency while in a power-managed mode. if the a/d is expected to operate while the device is in a power-managed mode, the acqt2:acqt0 and adcs2:adcs0 bits in adcon2 should be updated in accordance with the clock source to be used in that mode. after entering the mode, an a/d acquisition or conversion may be started. once started, the device should continue to be clocked by the same clock source until the conversion has been completed. if desired, the device may be placed into the corresponding idle mode during the conversion. if the device clock frequency is less than 1 mhz, the a/d rc clock source should be selected. operation in sleep mode requires the a/d f rc clock to be selected. if bits acqt2:acqt0 are set to ? 000 ? and a conversion is started, the conversion will be delayed one instruction cycle to allow execution of the sleep instruction and entry to sleep mode. the idlen bit (osccon<7>) must have already been cleared prior to starting the conversion. 15.6 configuring analog port pins the adcon1 and trisa registers configure the a/d port pins. the port pins needed as analog inputs must have their corresponding tris bits set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. the a/d operation is independent of the state of the chs1:chs0 bits and the tris bits. note 1: when reading the port register, all pins configured as analog input channels will read as cleared (a low level). pins configured as digital inputs will convert as analog inputs. analog levels on a digitally configured input will be accurately converted. 2: analog levels on any pin defined as a digital input may cause the digital input buffer to consume current out of the device?s specification limits.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 171 15.7 a/d conversions figure 15-4 shows the operation of the a/d converter after the go/done bit has been set and the acqt2:acqt0 bits are cleared. a conversion is started after the following instruction to allow entry into sleep mode before the conversion begins. figure 15-5 shows the operation of the a/d converter after the go/done bit has been set, the acqt2:acqt0 bits are set to ? 010 ? and a 4 t ad acquisition time is selected before the conversion starts. clearing the go/done bit during a conversion will abort the current conversion. the a/ d result register pair will not be updated with the partially completed a/d conversion sample. this means that the adresh:adresl registers will continue to contain the value of the last completed conversion (or the last value written to the adresh:adresl registers). after the a/d conversion is completed or aborted, a 2t ad wait is required before the next acquisition can be started. after this wait, acquisition on the selected channel is automatically started. 15.8 discharge the discharge phase is used to initialize the value of the capacitor array. the array is discharged before every sample. this feature helps to optimize the unity- gain amplifier, as the circuit always needs to charge the capacitor array, rather than charge/discharge based on previous measure values. figure 15-4: a/d conversion t ad cycles (acqt<2:0> = 000 , t acq = 0 ) figure 15-5: a/d conversion t ad cycles (acqt<2:0> = 010 , t acq = 4 t ad ) note: the go/done bit should not be set in the same instruction that turns on the a/d. t ad 1 t ad 2 t ad 3 t ad 4 t ad 5 t ad 6 t ad 7 t ad 8 t ad 11 set go/done bit holding capacitor is disconnected from analog input (typically 100 ns) t ad 9 t ad 10 t cy ? t ad adresh:adresl are loaded, go/done bit is cleared, adif bit is set, holding capacitor is connected to analog input. conversion starts b0 b9 b6 b5 b4 b3 b2 b1 b8 b7 on the following cycle: t ad 1 discharge 1 2 3 4 5 6 7 8 11 set go/done bit (holding capacitor is disconnected) 9 10 conversion starts 1 2 3 4 (holding capacitor continues acquiring input) t acqt cycles t ad cycles automatic acquisition time b0 b9 b6 b5 b4 b3 b2 b1 b8 b7 adresh:adresl are loaded, go/done bit is cleared, adif bit is set, holding capacitor is connected to analog input. on the following cycle: t ad 1 discharge
pic18f1230/1330 ds39758b-page 172 advance information ? 2006 microchip technology inc. table 15-2: registers associated with a/d operation name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ?adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ?adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ?adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 adresh a/d result register high byte 42 adresl a/d result register low byte 42 adcon0 sevten ? ? ? chs1 chs0 go/done adon 42 adcon1 ? ? ? vcfg0 pcfg3 pcfg2 pcfg1 pcfg0 42 adcon2 adfm ? acqt2 acqt1 acqt0 adcs2 adcs1 adcs0 42 porta ra7 (1) ra6 (1) ra5 (2) ra4 ra3 ra2 ra1 ra0 44 trisa trisa7 (1) trisa6 (1) porta data direction control register 43 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used for a/d conversion. note 1: porta<7:6> and their direction bits are individually configured as port pins based on various primary oscillator modes. when disabled, these bits read as ? 0 ?. 2: the ra5 bit is only available when master clear reset is disabled (mclre configuration bit = 0 ); otherwise, ra5 reads as ? 0 ?. this bit is read-only.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 173 16.0 comparator module the analog comparator module contains three comparators. the inputs can be selected from the analog inputs multiplexed with pins ra0, rb2 and rb3, as well as the on-chip voltage reference (see section 17.0 ?comparator voltage reference module? ). the digital outputs are not available at the pin level and can only be read through the control register, cmcon (register 16-1). cmcon also selects the comparator input. register 16-1: cmcon: co mparator control register r-0 r-0 r-0 u-0 u-0 r/w-0 r/w-0 r/w-0 c2out c1out c0out ? ? cmen2 cmen1 cmen0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 c2out : comparator 2 output bit 1 = c2 v in + > c2 v in - (cv ref ) 0 = c2 v in + < c2 v in - (cv ref ) bit 6 c1out : comparator 1 output bit 1 = c1 v in + > c1 v in - (cv ref ) 0 = c1 v in + < c1 v in - (cv ref )- bit 5 c0out : comparator 0 output bit 1 = c0 v in + > c0 v in - (cv ref ) 0 = c0 v in + < c0 v in - (cv ref ) bit 4-3 unimplemented: read as ? 0 ? bit 2 cmen2 : comparator 2 enable bit 1 = comparator 2 is enabled 0 = comparator 2 is disabled bit 1 cmen1 : comparator 1 enable bit 1 = comparator 1 is enabled 0 = comparator 1 is disabled bit 0 cmen0 : comparator 0 enable bit 1 = comparator 0 is enabled 0 = comparator 0 is disabled
pic18f1230/1330 ds39758b-page 174 advance information ? 2006 microchip technology inc. 16.1 comparator configuration for every analog comparator, there is a control bit called cmenx in the cmcon register. by setting the cmenx bit, the corresponding comparator can be enabled. if the comparator mode is changed, the comparator output level may not be valid for the specified mode change delay shown in section 22.0 ?electrical characteristics? . 16.2 comparator operation a single comparator is shown in figure 16-1, along with the relationship between the analog input levels and the digital output. when the analog input at v in + (cmpx) is less than the analog input v in - (cv ref ), the output of the comparator is a digital low level. when the analog input at v in + (cmpx) is greater than the analog input v in - (cv ref ), the output of the comparator is a digital high level. the shaded areas of the output of the comparator in figure 16-1 represent the uncertainty due to input offsets and response time. 16.3 comparator reference in this comparator module, an internal voltage reference is used (see section 17.0 ?comparator voltage reference module? ). figure 16-1: single comparator 16.4 comparator response time response time is the minimum time, after selecting a new reference voltage or input source, before the comparator output has a valid level. if the internal reference is changed, the maximum delay of the internal voltage reference must be considered when using the comparator outputs. otherwise, the maximum delay of the comparators should be used (see section 22.0 ?electrical characteristics? ). 16.5 comparator outputs the comparator outputs are read through the cxout bits of the cmcon register. these bits are read-only. the uncertainty of each of the comparators is related to the input offset voltage and the response time given in the specifications. 16.6 comparator interrupts the comparator interrupt flag is set whenever there is a change in the output value of the corresponding comparator. software will need to maintain information about the status of the output bits, as read from cmcon<7:5>, to determine the actual change that occurred. the cmpxif bit (pir1<3:1>) is the comparator interrupt flag. the cmpxif bit must be reset by clearing it. since it is also possible to write a ? 1 ? to this register, a simulated interrupt may be initiated. both the cmpxie bit (pie1<3:1>) and the peie bit (intcon<6>) must be set to enable the interrupt for the corresponding comparator. in addition, the gie bit (intcon<7>) must also be set. if any of these bits are clear, the interrupt is not enabled, though the cmpxif bit will still be set if an interrupt condition occurs. the user, in the interrupt service routine, can clear the interrupt in the following manner: a) any read or write of cmcon will end the mismatch condition. b) clear flag bit cmpxif. a mismatch condition will continue to set flag bit cmpxif. reading cmcon will end the mismatch condition and allow flag bit cmpxif to be cleared. note: comparator interrupts should be disabled during a comparator mode change; otherwise, a false interrupt may occur. - + v in + output output v in - v in + v in - note 1: when reading the port register, all pins configured as analog inputs will read as a ? 0 ?. pins configured as digital inputs will convert an analog input according to the schmitt trigger input specification. 2: analog levels on any pin defined as a digital input may cause the input buffer to consume more current than is specified. note: if a change in the cmcon register (c2out, c1out or c0out) should occur when a read operation is being executed (start of the q2 cycle), then the cmpxif (pir1 register) interrupt flag may not get set.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 175 16.7 comparator operation during sleep when a comparator is active and the device is placed in sleep mode, the comparator remains active and the interrupt is functional if enabled. this interrupt will wake-up the device from sleep mode when enabled. each operational comparator will consume additional current, as shown in the comparator specifications. to minimize power consumption while in sleep mode, turn off the comparators (cmen2:cmen0 = 000 ) before entering sleep. if the device wakes up from sleep, the contents of the cmcon register are not affected. 16.8 effects of a reset a device reset forces the cmcon register to its reset state, causing the comparator modules to be turned off (cmen2:cmen0 = 000) . 16.9 analog input connection considerations a simplified circuit for an analog input is shown in figure 16-2. since the analog pins are connected to a digital output, they have reverse biased diodes to v dd and v ss . the analog input, therefore, must be between v ss and v dd . if the input voltage deviates from this range by more than 0.6v in either direction, one of the diodes is forward biased and a latch-up condition may occur. a maximum source impedance of 10 k is recommended for the analog sources. any external component connected to an analog input pin, such as a capacitor or zener diode, should have very little leakage current. figure 16-2: comparator analog input model va r s < 10k a in c pin 5 pf v dd v t = 0.6v v t = 0.6v r ic i leakage 500 na v ss legend: c pin = input capacitance v t = threshold voltage i leakage = leakage current at the pin due to various junctions r ic = interconnect resistance r s = source impedance va = analog voltage comparator input
pic18f1230/1330 ds39758b-page 176 advance information ? 2006 microchip technology inc. table 16-1: registers associated with comparator module name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page cmcon c2out c1out c0out ? ? cmen2 cmen1 cmen0 42 cvrcon cvren ?cvrr cvrss cvr3 cvr2 cvr1 cvr0 42 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir1 ? adif rcif txif cmp2if cmp1if cmp0if tmr1if 43 pie1 ? adie rcie txie cmp2ie cmp1ie cmp0ie tmr1ie 43 ipr1 ? adip rcip txip cmp2ip cmp1ip cmp0ip tmr1ip 43 porta ra7 (1) ra6 (1) ra5 (2) ra4 ra3 ra2 ra1 ra0 44 lata lata7 (1) lata6 (1) porta data latch register (read and write to data latch) 43 trisa trisa7 (1) trisa6 (1) porta data direction control register 43 portb rb7 rb6 rb5 rb4 rb3 rb2 rb1 rb0 44 latb portb data latch register (read and write to data latch) 43 trisb portb data direction control register 43 legend: ? = unimplemented, read as ? 0 ?. shaded cells are unused by the comparator module. note 1: porta<7:6> and their direction and latch bits are individually configured as port pins based on various primary oscillator modes. when disabled, these bits read as ? 0 ?. 2: the ra5 bit is only available when master clear reset is disabled (mclre configuration bit = 0 ); otherwise, ra5 reads as ? 0 ?. this bit is read-only.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 177 17.0 comparator voltage reference module the comparator voltage reference is a 16-tap resistor ladder network that provides a selectable reference voltage. its purpose is to provide a reference for the analog comparators. a block diagram of the module is shown in figure 17-1. the resistor ladder is segmented to provide two ranges of cv ref values and has a power-down function to conserve power when the reference is not being used. the module?s supply reference can be provided from either device v dd /v ss or an external voltage reference. 17.1 configuring the comparator voltage reference the voltage reference module is controlled through the cvrcon register (register 17-1). the comparator voltage reference provides two ranges of output voltage, each with 16 distinct levels. the range to be used is selected by the cvrr bit (cvrcon<5>). the primary difference between the ranges is the size of the steps selected by the cv ref selection bits (cvr3:cvr0), with one range offering finer resolution. the equations used to calculate the output of the comparator voltage reference are as follows: if cvrr = 1 : cv ref = ((cvr3:cvr0)/24) x cv rsrc if cvrr = 0 : cv ref = (cv rsrc x 1/4) + (((cvr3:cvr0)/32) x cv rsrc ) the comparator reference supply voltage can come from either av dd or av ss , or the external v ref + that is multiplexed with ra4 and av ss . the voltage source is selected by the cvrss bit (cvrcon<4>). the settling time of the comparator voltage reference must be considered when changing the cv ref output (see table 22-3 in section 22.0 ?electrical characteristics? ). register 17-1: cvrcon: comparator vo ltage reference control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren ? cvrr cvrss cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 cvren : comparator voltage reference enable bit 1 =cv ref circuit powered on 0 =cv ref circuit powered down bit 6 unimplemented: read as ? 0 ? bit 5 cvrr : comparator v ref range selection bit 1 = 0 to 0.667 cv rsrc , with cv rsrc /24 step size (low range) 0 = 0.25 cv rsrc to 0.75 cv rsrc , with cv rsrc /32 step size (high range) bit 4 cvrss : comparator v ref source selection bit 1 = comparator reference source, cv rsrc = (v ref +) ? (av ss ) 0 = comparator reference source, cv rsrc = av dd ? av ss bit 3-0 cvr3:cvr0: comparator v ref value selection bits (0 (cvr3:cvr0) 15) when cvrr = 1 : cv ref = ((cvr3:cvr0)/24) ? (cv rsrc ) when cvrr = 0 : cv ref = (cv rsrc /4) + ((cvr3:cvr0)/32) ? (cv rsrc )
pic18f1230/1330 ds39758b-page 178 advance information ? 2006 microchip technology inc. figure 17-1: comparator voltage reference block diagram 17.2 voltage reference accuracy/error the full range of voltage reference cannot be realized due to the construction of the module. the transistors on the top and bottom of the resistor ladder network (figure 17-1) keep cv ref from approaching the reference source rails. the voltage reference is derived from the reference source; therefore, the cv ref output changes with fluctuations in that source. the tested absolute accuracy of the voltage reference can be found in section 22.0 ?electrical characteristics? . 17.3 operation during sleep when the device wakes up from sleep through an interrupt or a watchdog timer time-out, the contents of the cvrcon register are not affected. to minimize current consumption in sleep mode, the voltage reference should be disabled. 17.4 effects of a reset a device reset disables the voltage reference by clearing bit, cvren (cvrcon<7>). this reset selects the high- voltage range by clearing bit, cvrr (cvrcon<5>). the cvr value select bits are also cleared. table 17-1: registers associated with comparator voltage reference 16-to-1 mux cvr3:cvr0 8r r cvren cvrss = 0 av dd v ref + cvrss = 1 8r cvrss = x av ss r r r r r r 16 steps cvrr cv ref name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page cvrcon cvren ? cvrr cvrss cvr3 cvr2 cvr1 cvr0 42 cmcon c2out c1out c0out ? ? cmen2 cmen1 cmen0 42 legend: shaded cells are not used with the comparator voltage reference.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 179 18.0 low-voltage detect (lvd) pic18f1230/1330 devices have a low-voltage detect module (lvd). this is a programmable circuit that allows the user to specify the device voltage trip point. if the device experiences an excursion past the trip point, an interrupt flag is set. if the interrupt is enabled, the program execution will branch to the interrupt vector address and the software can then respond to the interrupt. the low-voltage detect control register (register 18-1) completely controls the operation of the lvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. the block diagram for the lvd module is shown in figure 18-1. register 18-1: lvdcon: low-volt age detect control register u-0 u-0 r-0 r/w-0 r/w-0 r/w-1 r/w-0 r/w-1 ? ? irvst lvden lvdl3 (1) lvdl2 (1) lvdl1 (1) lvdl0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 unimplemented: read as ? 0 ? bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the voltage detect logic will generate the interrupt flag at the specified voltage trip point 0 = indicates that the voltage detect logic will not generate the interrupt flag at the specified voltage trip point and the lvd interrupt should not be enabled bit 4 lvden: low-voltage detect power enable bit 1 = lvd enabled 0 = lvd disabled bit 3-0 lvdl3:lvdl0: voltage detection limit bits (1) 1111 = reserved 1110 = maximum setting . . . 0000 = minimum setting note 1: see table 22-4 in section 22.0 ?electrical characteristics? for the specifications.
pic18f1230/1330 ds39758b-page 180 advance information ? 2006 microchip technology inc. the module is enabled by setting the lvden bit. each time that the lvd module is enabled, the circuitry requires some time to stabilize. the irvst bit is a read-only bit and is used to indicate when the circuit is stable. the module can only generate an interrupt after the circuit is stable and irvst is set. 18.1 operation when the lvd module is enabled, a comparator uses an internally generated reference voltage as the set point. the set point is compared with the trip point, where each node in the resistor divider represents a trip point voltage. the ?trip point? voltage is the voltage level at which the device detects a low-voltage event depending on the configuration of the module. when the supply voltage is equal to the trip point, the voltage tapped off of the resistor array is equal to the internal reference voltage generated by the voltage reference module. the comparator then generates an interrupt signal by setting the lvdif bit. the trip point voltage is software programmable to any 1 of 15 values. the trip point is selected by programming the lvdl3:lvdl0 bits (lvdcon<3:0>). figure 18-1: lvd module block diagram set v dd 16-to-1 mux lvden lvdcon lvdl3:lvdl0 register lvdif lvden borenx internal voltage reference
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 181 18.2 lvd setup the following steps are needed to set up the lvd module: 1. disable the module by clearing the lvden bit (lvdcon<4>). 2. write the value to the lvdl3:lvdl0 bits that selects the desired lvd trip point. 3. enable the lvd module by setting the lvden bit. 4. clear the lvd interrupt flag (pir2<2>) which may have been set from a previous interrupt. 5. enable the lvd interrupt, if interrupts are desired, by setting the lvdie and gie bits (pie2<2> and intcon<7>). an interrupt will not be generated until the irvst bit is set. 18.3 current consumption when the module is enabled, the lvd comparator and voltage divider are enabled and will consume static cur- rent. the total current consumption, when enabled, is specified in electrical specification parameter d022b. depending on the application, the lvd module does not need to be operating constantly. to decrease the current requirements, the lvd circuitry may only need to be enabled for short periods where the voltage is checked. after doing the check, the lvd module may be disabled. 18.4 lvd start-up time the internal reference voltage of the lvd module, specified in electrical specification parameter d420, may be used by other internal circuitry, such as the programmable brown-out reset. if the lvd or other circuits using the voltage reference are disabled to lower the device?s current consumption, the reference voltage circuit will require time to become stable before a low-voltage condition can be reliably detected. this start-up time, t irvst , is an interval that is independent of device clock speed. it is specified in electrical specification parameter 36. the lvd interrupt flag is not enabled until t irvst has expired and a stable reference voltage is reached. for this reason, brief excursions beyond the set point may not be detected during this interval (refer to figure 18-2). figure 18-2: low-voltage detect operation v lvd v dd lvdif v lvd v dd enable lvd t irvst lvdif may not be set enable lvd lvdif lvdif cleared in software lvdif cleared in software lvdif cleared in software, case 1: case 2: lvdif remains set since lvd condition still exists t irvst internal reference is stable internal reference is stable irvst irvst
pic18f1230/1330 ds39758b-page 182 advance information ? 2006 microchip technology inc. 18.5 applications in many applications, the ability to detect a drop below a particular threshold is desirable. for general battery applications, figure 18-3 shows a possible voltage curve. over time, the device voltage decreases. when the device voltage reaches voltage v a , the lvd logic generates an interrupt at time t a . the interrupt could cause the execution of an isr, which would allow the application to perform ?housekeeping tasks? and perform a controlled shutdown before the device voltage exits the valid operating range at t b . the lvd, thus, would give the application a time win- dow, represented by the difference between t a and t b , to safely exit. figure 18-3: typical low-voltage detect application 18.6 operation during sleep when enabled, the lvd circuitry continues to operate during sleep. if the device voltage crosses the trip point, the lvdif bit will be set and the device will wake- up from sleep. device execution will continue from the interrupt vector address if interrupts have been globally enabled. 18.7 effects of a reset a device reset forces all registers to their reset state. this forces the lvd module to be turned off. table 18-1: registers associated with low-voltage detect module time voltage v a v b t a t b v a = lvd trip point v b = minimum valid device operating voltage legend: name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page lvdcon ? ? irvst lvden lvdl3 lvdl2 lvdl1 lvdl0 42 intcon gie/gieh peie/giel tmr0ie int0ie rbie tmr0if int0if rbif 41 pir2 oscfif ? ? eeif ?lvdif ? ?43 pie2 oscfie ? ? eeie ?lvdie ? ?43 ipr2 oscfip ? ? eeip ?lvdip ? ?43 legend: ? = unimplemented, read as ? 0 ?. shaded cells are unused by the lvd module.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 183 19.0 special features of the cpu pic18f1230/1330 devices include several features intended to maximize reliability and minimize cost through elimination of external components. these are: ? oscillator selection ? resets: - power-on reset (por) - power-up timer (pwrt) - oscillator start-up timer (ost) - brown-out reset (bor) ? interrupts ? watchdog timer (wdt) ? fail-safe clock monitor ? two-speed start-up ? code protection ? id locations ? in-circuit serial programming the oscillator can be configured for the application depending on frequency, power, accuracy and cost. all of the options are discussed in detail in section 2.0 ?oscillator configurations? . a complete discussion of device resets and interrupts is available in previous sections of this data sheet. in addition to their power-up and oscillator start-up timers provided for resets, pic18f1230/1330 devices have a watchdog timer, which is either permanently enabled via the configuration bits or software controlled (if configured as disabled). the inclusion of an internal rc oscillator also provides the additional benefits of a fail-safe clock monitor (fscm) and two-speed start-up. fscm provides for background monitoring of the peripheral clock and automatic switchover in the event of its failure. two- speed start-up enables code to be executed almost immediately on start-up while the primary clock source completes its start-up delays. all of these features are enabled and configured by setting the appropriate configuration register bits. 19.1 configuration bits the configuration bits can be programmed (read as ? 0 ?) or left unprogrammed (read as ? 1 ?) to select various device configurations. these bits are mapped starting at program memory location 300000h. the user will note that address 300000h is beyond the user program memory space. in fact, it belongs to the configuration memory space (300000h-3fffffh) which can only be accessed using table reads and table writes. programming the configuration registers is done in a manner similar to programming the flash memory. the wr bit in the eecon1 register starts a self-timed write to the configuration register. in normal operation mode, a tblwt instruction with the tblptr pointing to the configuration register sets up the address and data for the configuration register write. setting the wr bit starts a long write to the configuration register. the configuration registers are written a byte at a time. to write or erase a configuration cell, a tblwt instruction can write a ? 1 ? or a ? 0 ? into the cell. for additional details on flash programming, refer to section 6.5 ?writing to flash program memory? . table 19-1: configuration bits and device ids file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 default/ unprogrammed value 300001h config1h ieso fcmen ? ? fosc3 fosc2 fosc1 fosc0 00-- 0111 300002h config2l ? ? ? borv1 borv0 boren1 boren0 pwrten ---1 1111 300003h config2h ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 wdten ---1 1111 300004h config3l ? ? ? ? hpol lpol pwmpin ? ---- 111- 300005h config3h mclre ? ? ?t1oscmx ? ?fltamx 1--- 0--1 300006h config4l bkbug xinst bbsiz1 bbsiz0 ? ? ?stvren 1000 ---1 300008h config5l ? ? ? ? ? ?cp1cp0 ---- --11 300009h config5h cpd cpb ? ? ? ? ? ? 11-- ---- 30000ah config6l ? ? ? ? ? ? wrt1 wrt0 ---- --11 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 111- ---- 30000ch config7l ? ? ? ? ? ? ebtr1 ebtr0 ---- --11 30000dh config7h ?ebtrb ? ? ? ? ? ? -1-- ---- 3ffffeh devid1 (1) dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 see table 19-2 3fffffh devid2 (1) dev10 dev9 dev8 dev7 deev6 dev5 dev4 dev3 see table 19-2 legend: - = unimplemented, read as ? 0 ?.shaded cells are unimp lemented, read as ? 0 ?. note 1: devid registers are read-only and c annot be programmed by the user.
pic18f1230/1330 ds39758b-page 184 advance information ? 2006 microchip technology inc. register 19-1: config1h: configuration register 1 high (byte address 300001h) r/p-0 r/p-0 u-0 u-0 r/p-0 r/p-1 r/p-1 r/p-1 ieso fcmen ? ? fosc3 fosc2 fosc1 fosc0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7 ieso: internal/external oscillator switchover bit 1 = oscillator switchover mode enabled 0 = oscillator switchover mode disabled bit 6 fcmen: fail-safe clock monitor enable bit 1 = fail-safe clock monitor enabled 0 = fail-safe clock monitor disabled bit 5-4 unimplemented: read as ? 0 ? bit 3-0 fosc3:fosc0: oscillator selection bits 11xx = external rc oscillator, clko function on ra6 101x = external rc oscillator, clko function on ra6 1001 = internal oscillator block, clko function on ra6, port function on ra7 1000 = internal oscillator block, port function on ra6 and ra7 0111 = external rc oscillator, port function on ra6 0110 = hs oscillator, pll enabled (clock frequency = 4 x fosc1) 0101 = ec oscillator, port function on ra6 0100 = ec oscillator, clko function on ra6 0011 = external rc oscillator, clko function on ra6 0010 = hs oscillator 0001 = xt oscillator 0000 = lp oscillator
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 185 register 19-2: config2l: configuration register 2 low (byte address 300002h) u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 ? ? ?borv1 (1) borv0 (1) boren1 (2) boren0 (2) pwrten (2) bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-5 unimplemented: read as ? 0 ? bit 4-3 borv1:borv0: brown-out reset voltage bits (1) 11 = minimum setting ? ? ? 00 = maximum setting bit 2-1 boren1:boren0: brown-out reset enable bits (2) 11 = brown-out reset enabled in hardware only (sboren is disabled) 10 = brown-out reset enabled in hardware only and disabled in sleep mode (sboren is disabled) 01 = brown-out reset enabled and controlled by software (sboren is enabled) 00 = brown-out reset disabled in hardware and software bit 0 pwrten : power-up timer enable bit (2) 1 = pwrt disabled 0 = pwrt enabled note 1: see section 22.1 ?dc characteristics? for the specifications. 2: the power-up timer is decoupled from brown-out reset, allowing these features to be independently controlled.
pic18f1230/1330 ds39758b-page 186 advance information ? 2006 microchip technology inc. register 19-3: config2h: configuration register 2 high (byte address 300003h) u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 ? ? ? wdtps3 wdtps2 wdtps1 wdtps0 wdten bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-5 unimplemented: read as ? 0 ? bit 4-1 wdtps3:wdtps0: watchdog timer postscale select bits 1111 = 1:32,768 1110 = 1:16,384 1101 = 1:8,192 1100 = 1:4,096 1011 = 1:2,048 1010 = 1:1,024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1 bit 0 wdten: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled (control is placed on the swdten bit)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 187 register 19-4: config3l: configuration register 3 low (byte address 300005h) u-0 u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 u-0 ? ? ? ?hpol (1) lpol (1) pwmpin ? bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-4 unimplemented: read as ? 0 ? bit 3 hpol: high side transistors polarity bit (odd pwm output polarity control bit) (1) 1 = pwm1, pwm3 and pwm5 are active-high (default) 0 = pwm1, pwm3 and pwm5 are active-low bit 2 lpol: low side transistors polarity bit (even pwm output polarity control bit) (1) 1 = pwm0, pwm2 and pwm4 are active-high (default) 0 = pwm0, pwm2 and pwm4 are active-low bit 2 pwmpin: pwm output pins reset state control bit 1 = pwm outputs disabled upon reset 0 = pwm outputs drive active states upon reset (2) bit 0 unimplemented: read as ? 0 ? note 1: polarity control bits, hpol and lpol, define pwm signal output active and inactive states, pwm states generated by the fault inputs or pwm manual override. 2: when pwmpin = 0 , pwmen<2:0> = 100 . pwm output polarity is defined by hpol and lpol.
pic18f1230/1330 ds39758b-page 188 advance information ? 2006 microchip technology inc. register 19-5: config3h: configuration register 3 high (byte address 300005h) r/p-1 u-0 u-0 u-0 r/p-0 u-0 u-0 r/p-1 mclre ? ? ?t1oscmx ? ?fltamx bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7 mclre: mclr pin enable bit 1 =mclr pin enabled, ra5 input pin disabled 0 = ra5 input pin enabled, mclr pin disabled bit 6-4 unimplemented: read as ? 0 ? bit 3 t1oscmx: t1oso/t1cki mux bit 1 = t1oso/t1cki pin resides on ra6 0 = t1oso/t1cki pin resides on rb2 bit 2-1 unimplemented: read as ? 0 ? bit 0 fltamx: flta mux bit 1 = flta is muxed onto ra5 0 = flta is muxed onto ra7
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 189 register 19-6: config4l: configuration register 4 low (byte address 300006h) r/p-1 r/p-0 r/p-0 r/p-0 u-0 u-0 u-0 r/p-1 bkbug xinst bbsiz1 bbsiz0 ? ? ?stvren bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7 bkbug : background debugger enable bit 1 = background debugger disabled, rb6 and rb7 configured as general purpose i/o pins 0 = background debugger enabled, rb6 and rb7 are dedicated to in-circuit debug bit 6 xinst: extended instruction set enable bit 1 = instruction set extension and indexed addressing mode enabled 0 = instruction set extension and indexed addressing mode disabled bit 5-4 bbsiz<1:0>: boot block size select bits for pic18f1330 device : 11 = 1 kw boot block size 10 = 1 kw boot block size 01 = 512w boot block size 00 = 256w boot block size for pic18f1230 device : 11 = 512w boot block size 10 = 512w boot block size 01 = 512w boot block size 00 = 256w boot block size bit 3-1 unimplemented: read as ? 0 ? bit 0 stvren: stack overflow/underflow reset enable bit 1 = reset on stack overflow/underflow enabled 0 = reset on stack overflow/underflow disabled
pic18f1230/1330 ds39758b-page 190 advance information ? 2006 microchip technology inc. register 19-7: config5l: configuration register 5 low (byte address 300008h) u-0 u-0 u-0 u-0 u-0 u-0 r/c-1 r/c-1 ? ? ? ? ? ?cp1cp0 bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-2 unimplemented: read as ? 0 ? bit 1 cp1: code protection bit (block 1 code memory area) 1 = block 1 is not code-protected 0 = block 1 is code-protected bit 0 cp0: code protection bit (block 0 code memory area) 1 = block 0 is not code-protected 0 = block 0 is code-protected register 19-8: config5h: configuration register 5 high (byte address 300009h) r/c-1 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 cpd cpb ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7 cpd: code protection bit (data eeprom) 1 = data eeprom is not code-protected 0 = data eeprom is code-protected bit 6 cpb: code protection bit (boot block memory area) 1 = boot block is not code-protected 0 = boot block is code-protected bit 5-0 unimplemented: read as ? 0 ?
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 191 register 19-9: config6l: configuration register 6 low (byte address 30000ah) u-0 u-0 u-0 u-0 u-0 u-0 r/c-1 r/c-1 ? ? ? ? ? ?wrt1wrt0 bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-2 unimplemented: read as ? 0 ? bit 1 wrt1: write protection bit (block 1 code memory area) 1 = block 1 is not write-protected 0 = block 1 is write-protected bit 0 wrt0: write protection bit (block 0 code memory area) 1 = block 0 is not write-protected 0 = block 0 is write-protected register 19-10: config6h: configuration register 6 high (byte address 30000bh) r/c-1 r/c-1 r-1 u-0 u-0 u-0 u-0 u-0 wrtd wrtb wrtc (1) ? ? ? ? ? bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7 wrtd: write protection bit (data eeprom) 1 = data eeprom is not write-protected 0 = data eeprom is write-protected bit 6 wrtb: write protection bit (boot block memory area) 1 = boot block is not write-protected 0 = boot block is write-protected bit 5 wrtc: write protection bit (configuration registers) (1) 1 = configuration registers are not write-protected 0 = configuration registers are write-protected bit 4-0 unimplemented: read as ? 0 ? note 1: this bit is read-only in normal execution mode; it can be written only in program mode.
pic18f1230/1330 ds39758b-page 192 advance information ? 2006 microchip technology inc. register 19-11: config7l: configuration register 7 low (byte address 30000ch) u-0 u-0 u-0 u-0 u-0 u-0 r/c-1 r/c-1 ? ? ? ? ? ? ebtr1 ebtr0 bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-2 unimplemented: read as ? 0 ? bit 1 ebtr1: table read protection bit (block 1 code memory area) 1 = block 1 is not protected from table reads executed in other blocks 0 = block 1 is protected from table reads executed in other blocks bit 0 ebtr0: table read protection bit (block 0 code memory area) 1 = block 0 is not protected from table reads executed in other blocks 0 = block 0 is protected from table reads executed in other blocks register 19-12: config7h: configuration register 7 high (byte address 30000dh) u-0 r/c-1 u-0 u-0 u-0 u-0 u-0 u-0 ? ebtrb ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7 unimplemented: read as ? 0 ? bit 6 ebtrb: table read protection bit (boot block memory area) 1 = boot block is not protected from table reads executed in other blocks 0 = boot block is protected from table reads executed in other blocks bit 5-0 unimplemented: read as ? 0 ?
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 193 register 19-13: devid1: device id register 1 for pic18f1230/1330 devices rrrrrrrr dev2 dev1 dev0 rev4 rev3 rev2 rev1 rev0 bit 7 bit 0 legend: r = read-only bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-5 dev2:dev0: device id bits these bits are used with the dev10:dev3 bits in the devid2 register to identify part number. bit 4-0 rev3:rev0: revision id bits these bits are used to indicate the device revision. register 19-14: devid2: device id register 2 for pic18f1230/1330 devices rrrrrrrr dev10 dev9 dev8 dev7 dev6 dev5 dev4 dev3 bit 7 bit 0 legend: r = read-only bit p = programmable bit u = unimplemented bit, read as ?0? -n = value when device is unprogrammed u = unchanged from programmed state bit 7-0 dev10:dev3: device id bits these bits are used with the dev2:dev0 bits in the devid1 register to identify part number.
pic18f1230/1330 ds39758b-page 194 advance information ? 2006 microchip technology inc. 19.2 watchdog timer (wdt) for pic18f1230/1330 devices, the wdt is driven by the intrc source. when the wdt is enabled, the clock source is also enabled. the nominal wdt period is 4 ms and has the same stability as the intrc oscillator. the 4 ms period of the wdt is multiplied by a 16-bit postscaler. any output of the wdt postscaler is selected by a multiplexer, controlled by bits in configu- ration register 2h. available periods range from 4 ms to 131.072 seconds (2.18 minutes). the wdt and postscaler are cleared when any of the following events occur: a sleep or clrwdt instruction is executed, the ircf bits (osccon<6:4>) are changed or a clock failure has occurred. 19.2.1 control register register 19-15 shows the wdtcon register. this is a readable and writable register which contains a control bit that allows software to override the wdt enable configuration bit, but only if the configuration bit has disabled the wdt. figure 19-1: wdt block diagram note 1: the clrwdt and sleep instructions clear the wdt and postscaler counts when executed. 2: changing the setting of the ircf bits (osccon<6:4>) clears the wdt and postscaler counts. 3: when a clrwdt instruction is executed, the postscaler count will be cleared. intrc source wdt wake-up from reset wdt counter programmable postscaler 1:1 to 1:32,768 enable wdt wdtps<3:0> swdten wdten clrwdt 4 power-managed reset all device resets sleep 128 change on ircf bits modes
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 195 table 19-2: summary of watchdog timer registers register 19-15: wdtcon: watchdog timer control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 ? ? ? ? ? ? ?swdten (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-1 unimplemented: read as ? 0 ? bit 0 swdten: software controlled watchdog timer enable bit (1) 1 = watchdog timer is on 0 = watchdog timer is off note 1: this bit has no effect if the configuration bit, wdten, is enabled. name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 reset values on page rcon ipen sboren (1) ? ri to pd por bor 42 wdtcon ? ? ? ? ? ? ?swdten (2) 42 legend: ? = unimplemented, read as ? 0 ?. shaded cells are not used by the watchdog timer. note 1: the sboren bit is only available when the boren1:boren0 configuration bits = 01 ; otherwise, it is disabled and reads as ? 0 ?. see section 4.4 ?brown-out reset (bor)? . 2: this bit has no effect if the configuration bit, wdten, is enabled.
pic18f1230/1330 ds39758b-page 196 advance information ? 2006 microchip technology inc. 19.3 two-speed start-up the two-speed start-up feature helps to minimize the latency period from oscillator start-up to code execution by allowing the microcontroller to use the intosc oscillator as a clock source until the primary clock source is available. it is enabled by setting the ieso configuration bit. two-speed start-up should be enabled only if the primary oscillator mode is lp, xt, hs or hspll (crystal-based modes). other sources do not require an ost start-up delay; for these, two-speed start-up should be disabled. when enabled, resets and wake-ups from sleep mode cause the device to configure itself to run from the internal oscillator block as the clock source, following the time-out of the power-up timer, after a power-on reset is enabled. this allows almost immediate code execution while the primary oscillator starts and the ost is running. once the ost times out, the device automatically switches to pri_run mode. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf2:ircf0, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf2:ircf0 bits prior to entering sleep mode. in all other power-managed modes, two-speed start-up is not used. the device will be clocked by the currently selected clock source until the primary clock source becomes available. the setting of the ieso bit is ignored. 19.3.1 special considerations for using two-speed start-up while using the intosc oscillator in two-speed start-up, the device still obeys the normal command sequences for entering power-managed modes, including multiple sleep instructions (refer to section 3.1.4 ?multiple sleep commands? ). in practice, this means that user code can change the scs1:scs0 bit settings or issue sleep instructions before the ost times out. this would allow an applica- tion to briefly wake-up, perform routine ?housekeeping? tasks and return to sleep before the device starts to operate from the primary oscillator. user code can also check if the primary clock source is currently providing the device clocking by checking the status of the osts bit (osccon<3>). if the bit is set, the primary oscillator is providing the clock. otherwise, the internal oscillator block is providing the clock during wake-up from reset or sleep mode. figure 19-2: timing transition for two-speed start-up (intosc to hspll) q1 q3 q4 osc1 peripheral program pc pc + 2 intosc pll clock q1 pc + 6 q2 output q3 q4 q1 cpu clock pc + 4 clock counter q2 q2 q3 note 1: t ost = 1024 t osc ; t pll = 2 ms (approx). these intervals are not shown to scale. 2: clock transition typically occurs within 2-4 t osc . wake from interrupt event t pll (1) 12 n-1n clock osts bit set transition (2) multiplexer t ost (1)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 197 19.4 fail-safe clock monitor the fail-safe clock monitor (fscm) allows the microcontroller to continue operation in the event of an external oscillator failure by automatically switching the device clock to the internal oscillator block. the fscm function is enabled by setting the fcmen configuration bit. when fscm is enabled, the intrc oscillator runs at all times to monitor clocks to peripherals and provide a backup clock in the event of a clock failure. clock monitoring (shown in figure 19-3) is accomplished by creating a sample clock signal, which is the intrc output divided by 64. this allows ample time between fscm sample clocks for a peripheral clock edge to occur. the peripheral device clock and the sample clock are presented as inputs to the clock monitor latch (cm). the cm is set on the falling edge of the device clock source, but cleared on the rising edge of the sample clock. figure 19-3: fscm block diagram clock failure is tested for on the falling edge of the sample clock. if a sample clock falling edge occurs while cm is still set, a clock failure has been detected (figure 19-4). this causes the following: ? the fscm generates an oscillator fail interrupt by setting bit, oscfif (pir2<7>). ? the device clock source is switched to the internal oscillator block (osccon is not updated to show the current clock source ? this is the fail-safe condition). ?the wdt is reset. during switchover, the postscaler frequency from the internal oscillator block may not be sufficiently stable for timing sensitive applications. in these cases, it may be desirable to select another clock configuration and enter an alternate power-managed mode. this can be done to attempt a partial recovery or execute a controlled shut- down. see section 3.1.4 ?multiple sleep commands? and section 19.3.1 ?special considerations for using two-speed start-up? for more details. to use a higher clock speed on wake-up, the intosc or postscaler clock sources can be selected to provide a higher clock speed by setting bits, ircf2:ircf0, immediately after reset. for wake-ups from sleep, the intosc or postscaler clock sources can be selected by setting the ircf2:ircf0 bits prior to entering sleep mode. the fscm will detect failures of the primary or secondary clock sources only. if the internal oscillator block fails, no failure would be detected, nor would any action be possible. 19.4.1 fscm and the watchdog timer both the fscm and the wdt are clocked by the intrc oscillator. since the wdt operates with a separate divider and counter, disabling the wdt has no effect on the operation of the intrc oscillator when the fscm is enabled. as already noted, the clock source is switched to the intosc clock when a clock failure is detected. depending on the frequency selected by the ircf2:ircf0 bits, this may mean a substantial change in the speed of code execution. if the wdt is enabled with a small prescale value, a decrease in clock speed allows a wdt time-out to occur and a subsequent device reset. for this reason, fail-safe clock events also reset the wdt and postscaler, allowing it to start timing from when execution speed was changed and decreasing the likelihood of an erroneous time-out. 19.4.2 exiting fail-safe operation the fail-safe condition is terminated by either a device reset or by entering a power-managed mode. on reset, the controller starts the primary clock source specified in configuration register 1h (with any required start-up delays that are required for the oscillator mode, such as the ost or pll timer). the intosc multiplexer provides the device clock until the primary clock source becomes ready (similar to a two- speed start-up). the clock source is then switched to the primary clock (indicated by the osts bit in the osccon register becoming set). the fail-safe clock monitor then resumes monitoring the peripheral clock. the primary clock source may never become ready during start-up. in this case, operation is clocked by the intosc multiplexer. the osccon register will remain in its reset state until a power-managed mode is entered. peripheral intrc 64 s c q (32 s) 488 hz (2.048 ms) clock monitor latch (cm) (edge-triggered) clock failure detected source clock q
pic18f1230/1330 ds39758b-page 198 advance information ? 2006 microchip technology inc. figure 19-4: fscm timing diagram 19.4.3 fscm interrupts in power-managed modes by entering a power-managed mode, the clock multi- plexer selects the clock source selected by the osccon register. fail-safe clock monitoring of the power- managed clock source resumes in the power-managed mode. if an oscillator failure occurs during power-managed operation, the subsequent events depend on whether or not the oscillator failure interrupt is enabled. if enabled (oscfif = 1 ), code execution will be clocked by the intosc multiplexer. an automatic transition back to the failed clock source will not occur. if the interrupt is disabled, subsequent interrupts while in idle mode will cause the cpu to begin executing instructions while being clocked by the intosc source. 19.4.4 por or wake from sleep the fscm is designed to detect oscillator failure at any point after the device has exited power-on reset (por) or low-power sleep mode. when the primary device clock is ec, rc or intrc modes, monitoring can begin immediately following these events. for oscillator modes involving a crystal or resonator (hs, hspll, lp or xt), the situation is somewhat different. since the oscillator may require a start-up time considerably longer than the fcsm sample clock time, a false clock failure may be detected. to prevent this, the internal oscillator block is automatically configured as the device clock and functions until the primary clock is stable (the ost and pll timers have timed out). this is identical to two-speed start-up mode. once the primary clock is stable, the intrc returns to its role as the fscm source. as noted in section 19.3.1 ?special considerations for using two-speed start-up? , it is also possible to select another clock configuration and enter an alternate power-managed mode while waiting for the primary clock to become stable. when the new power- managed mode is selected, the primary clock is disabled. oscfif cm output device clock output sample clock failure detected oscillator failure note: the device clock is normally at a much higher frequency than the sample clock. the relative frequencies in this example have been chosen for clarity. (q ) cm test cm test cm test note: the same logic that prevents false oscilla- tor failure interrupts on por, or wake from sleep, will also prevent the detection of the oscillator?s failure to start at all follow- ing these events. this can be avoided by monitoring the osts bit and using a timing routine to determine if the oscillator is taking too long to start. even so, no oscillator failure interrupt will be flagged.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 199 19.5 program verification and code protection the overall structure of the code protection on the pic18 flash devices differs significantly from other picmicro ? devices. the user program memory is divided into three blocks. one of these is a boot block of variable size (maximum 2 kbytes). the remainder of the memory is divided into two blocks on binary boundaries. each of the three blocks has three code protection bits associated with them. they are: ? code-protect bit (cpx) ? write-protect bit (wrtx) ? external block table read bit (ebtrx) figure 19-5 shows the program memory organization for 4 and 8-kbyte devices and the specific code protection bit associated with each block. the actual locations of the bits are summarized in table 19-3. figure 19-5: code-protected prog ram memory for pic18f1230/1330 table 19-3: summary of code protection registers file name bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 300008h config5l ? ? ? ? ? ?cp1cp0 300009h config5h cpd cpb ? ? ? ? ? ? 30000ah config6l ? ? ? ? ? ?wrt1wrt0 30000bh config6h wrtd wrtb wrtc ? ? ? ? ? 30000ch config7l ? ? ? ? ? ? ebtr1 ebtr0 30000dh config7h ? ebtrb ? ? ? ? ? ? legend: shaded cells are unimplemented. memory size/device block code protection controlled by: 4kbytes (pic18f1230) 8kbytes (pic18f1330) address range boot block boot block 000000h 0003ffh cpb, wrtb, ebtrb block 0 000400h 0007ffh cp0, wrt0, ebtr0 block 1 block 0 000800h 000fffh cp1, wrt1, ebtr1 unimplemented read ? 0 ?s block 1 001000h 001fffh cp2, wrt2, ebtr2 unimplemented read ? 0 ?s unimplemented read ? 0 ?s 002000h 1fffffh (unimplemented memory space)
pic18f1230/1330 ds39758b-page 200 advance information ? 2006 microchip technology inc. 19.5.1 program memory code protection the program memory may be read to or written from any location using the table read and table write instructions. the device id may be read with table reads. the configuration registers may be read and written with the table read and table write instructions. in normal execution mode, the cpx bits have no direct effect. cpx bits inhibit external reads and writes. a block of user memory may be protected from table writes if the wrtx configuration bit is ? 0 ?. the ebtrx bits control table reads. for a block of user memory with the ebtrx bit set to ? 0 ?, a table read instruction that executes from within that block is allowed to read. a table read instruction that executes from a location outside of that block is not allowed to read and will result in reading ? 0 ?s. figures 19-6 through 19-8 illustrate table write and table read protection. figure 19-6: table write (wrtx) disallowed note: code protection bits may only be written to a ? 0 ? from a ? 1 ? state. it is not possible to write a ? 1 ? to a bit in the ? 0 ? state. code protection bits are only set to ? 1 ? by a full chip erase or block erase function. the full chip erase and block erase functions can only be initiated via icsp operation or an external programmer. 000000h 0007ffh 000800h 000fffh 001000h 001fffh wrtb, ebtrb = 11 wrt0, ebtr0 = 01 wrt1, ebtr1 = 11 tblwt* tblptr = 0008ffh pc = 000ffeh pc = 001800h register values program memory configuration bit settings results: all table writes disabled to blockn whenever wrtx = 0 . tblwt*
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 201 figure 19-7: external block table read (ebtrx) disallowed figure 19-8: external block table read (ebtrx) allowed wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 tblrd* tblptr = 0008ffh pc = 001100h results: all table reads from external blocks to blockn are disabled whenever ebtrx = 0 . tablat register returns a value of ? 0 ?. register values program memory configuration bit settings 000000h 0007ffh 000800h 000fffh 001000h 001fffh wrtb, ebtrb = 11 wrt0, ebtr0 = 10 wrt1, ebtr1 = 11 tblrd* tblptr = 0008ffh pc = 000ffeh register values program memory configuration bit settings results: table reads permitted within blockn, even when ebtrbx = 0 . tablat register returns the value of the data at the location tblptr. 000000h 0007ffh 000800h 000fffh 001000h 001fffh
pic18f1230/1330 ds39758b-page 202 advance information ? 2006 microchip technology inc. 19.5.2 data eeprom code protection the entire data eeprom is protected from external reads and writes by two bits: cpd and wrtd. cpd inhibits external reads and writes of data eeprom. wrtd inhibits internal and external writes to data eeprom. the cpu can always read data eeprom under normal operation, regardless of the protection bit settings. 19.5.3 configuration register protection the configuration registers can be write-protected. the wrtc bit controls protection of the configuration registers. in normal execution mode, the wrtc bit is read-only. wrtc can only be written via icsp operation or an external programmer. 19.6 id locations eight memory locations (200000h-200007h) are designated as id locations, where the user can store checksum or other code identification numbers. these locations are both readable and writable during normal execution through the tblrd and tblwt instructions or during program/verify. the id locations can be read when the device is code-protected. 19.7 in-circuit serial programming pic18f1230/1330 microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock and data and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed. 19.8 in-circuit debugger when the bkbug configuration bit is programmed to a ? 0 ?, the in-circuit debugger functionality is enabled. this function allows simple debugging functions when used with mplab ? ide. when the microcontroller has this feature enabled, some resources are not available for general use. table 19-4 shows which resources are required by the background debugger. table 19-4: debugger resources to use the in-circuit debugger function of the microcon- troller, the design must implement in-circuit serial programming connections to mclr /v pp /ra5/flta , v dd , v ss , rb7/pwm5/pgd and rb6/pwm4/pgc. this will interface to the in-circuit debugger module available from microchip or one of the third party development tool companies. 19.9 single-supply icsp programming the pic18f1230/1330 device family does not support low-voltage icsp programming or lvp. this device family can only be programmed using high-voltage icsp programming. for more details, refer to the ?pic18f1230/1330 flash microcontroller programming specification? (ds39752). memory that is not code-protected can be erased using either a block erase, or erased row by row, then written at any specified v dd . if code-protected memory is to be erased, a block erase is required. i/o pins: rb6, rb7 stack: 2 levels program memory: 512 bytes data memory: 10 bytes
? 2006 microchip technology inc. advance information ds39758b-page 203 pic18f1230/1330 20.0 development support the picmicro ? microcontrollers are supported with a full range of hardware and software development tools: ? integrated development environment - mplab ? ide software ? assemblers/compilers/linkers - mpasm tm assembler - mplab c18 and mplab c30 c compilers -mplink tm object linker/ mplib tm object librarian - mplab asm30 assembler/linker/library ? simulators - mplab sim software simulator ?emulators - mplab ice 2000 in-circuit emulator - mplab ice 4000 in-circuit emulator ? in-circuit debugger - mplab icd 2 ? device programmers - picstart ? plus development programmer - mplab pm3 device programmer ? low-cost demonstration and development boards and evaluation kits 20.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? visual device initializer for easy register initialization ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as hi-tech software c compilers and iar c compilers the mplab ide allows you to: ? edit your source files (either assembly or c) ? one touch assemble (or compile) and download to picmicro mcu emulator and simulator tools (automatically updates all project information) ? debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic18f1230/1330 ds39758b-page 204 advance information ? 2006 microchip technology inc. 20.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all picmicro mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 20.3 mplab c18 and mplab c30 c compilers the mplab c18 and mplab c30 code development systems are complete ansi c compilers for microchip?s pic18 family of microcontrollers and dspic30f family of digital signal controllers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 20.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 20.5 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire dspic30f instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility 20.6 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the picmicro mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, as well as internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c18 and mplab c30 c compilers, and the mpasm and mplab asm30 assemblers. the software simulator offers the flexibility to develop and debug code outside of the laboratory environment, making it an excellent, economical software development tool.
? 2006 microchip technology inc. advance information ds39758b-page 205 pic18f1230/1330 20.7 mplab ice 2000 high-performance in-circuit emulator the mplab ice 2000 in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for picmicro microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator system with enhanced trace, trigger and data monitor- ing features. interchangeable processor modules allow the system to be easily reconfigured for emulation of different processors. the architecture of the mplab ice 2000 in-circuit emulator allows expansion to support new picmicro microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows ? 32-bit operating system were chosen to best make these features available in a simple, unified application. 20.8 mplab ice 4000 high-performance in-circuit emulator the mplab ice 4000 in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for high-end picmicro mcus and dspic dscs. software control of the mplab ice 4000 in-circuit emulator is provided by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 4000 is a premium emulator system, providing the features of mplab ice 2000, but with increased emulation memory and high-speed perfor- mance for dspic30f and pic18xxxx devices. its advanced emulator features include complex triggering and timing, and up to 2 mb of emulation memory. the mplab ice 4000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft windows 32-bit operating system were chosen to best make these features available in a simple, unified application. 20.9 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash picmicro mcus and can be used to develop for these and other picmicro mcus and dspic dscs. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost-effective, in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single stepping and watching variables, and cpu status and peripheral registers. running at full speed enables testing hardware and applications in real time. mplab icd 2 also serves as a development programmer for selected picmicro devices. 20.10 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program picmicro devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an sd/mmc card for file storage and secure data applications.
pic18f1230/1330 ds39758b-page 206 advance information ? 2006 microchip technology inc. 20.11 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it connects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most picmicro devices in dip packages up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 20.12 demonstration, development and evaluation boards a wide variety of demonstration, development and evaluation boards for various picmicro mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart ? battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. check the microchip web page (www.microchip.com) and the latest ?product selector guide? (ds00148) for the complete list of demonstration, development and evaluation kits.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 207 21.0 instruction set summary pic18f1230/1330 devices incorporate the standard set of 75 pic18 core instructions, as well as an extended set of 8 new instructions for the optimization of code that is recursive or that utilizes a software stack. the extended set is discussed later in this section. 21.1 standard instruction set the standard pic18 instruction set adds many enhancements to the previous picmicro ? mcu instruc- tion sets, while maintaining an easy migration from these picmicro mcu instruction sets. most instructions are a single program memory word (16 bits), but there are four instructions that require two program memory locations. each single-word instruction is a 16-bit word divided into an opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories: ? byte-oriented operations ? bit-oriented operations ? literal operations ? control operations the pic18 instruction set summary in table 21-2 lists byte-oriented , bit-oriented , literal and control operations. table 21-1 shows the opcode field descriptions. most byte-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the destination of the result (specified by ?d?) 3. the accessed memory (specified by ?a?) the file register designator ?f? specifies which file register is to be used by the instruction. the destination designator ?d? specifies where the result of the operation is to be placed. if ?d? is zero, the result is placed in the wreg register. if ?d? is one, the result is placed in the file register specified in the instruction. all bit-oriented instructions have three operands: 1. the file register (specified by ?f?) 2. the bit in the file register (specified by ?b?) 3. the accessed memory (specified by ?a?) the bit field designator ?b? selects the number of the bit affected by the operation, while the file register designator ?f? represents the number of the file in which the bit is located. the literal instructions may use some of the following operands: ? a literal value to be loaded into a file register (specified by ?k?) ? the desired fsr register to load the literal value into (specified by ?f?) ? no operand required (specified by ???) the control instructions may use some of the following operands: ? a program memory address (specified by ?n?) ? the mode of the call or return instructions (specified by ?s?) ? the mode of the table read and table write instructions (specified by ?m?) ? no operand required (specified by ???) all instructions are a single word, except for four double-word instructions. these instructions were made double-word to contain the required information in 32 bits. in the second word, the 4 msbs are ? 1 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . all single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter is changed as a result of the instruction. in these cases, the execution takes two instruction cycles, with the additional instruction cycle(s) executed as a nop . the double-word instructions execute in two instruction cycles. one instruction cycle consists of four oscillator periods. thus, for an oscillator frequency of 4 mhz, the normal instruction execution time is 1 s. if a conditional test is true, or the program counter is changed as a result of an instruction, the instruction execution time is 2 s. two-word branch instructions (if true) would take 3 s. figure 21-1 shows the general formats that the instructions can have. all examples use the convention ?nnh? to represent a hexadecimal number. the instruction set summary, shown in table 21-2, lists the standard instructions recognized by the microchip mpasm? assembler. section 21.1.1 ?standard instruction set? provides a description of each instruction.
pic18f1230/1330 ds39758b-page 208 advance information ? 2006 microchip technology inc. table 21-1: opcode field descriptions field description a ram access bit a = 0 : ram location in access ram (bsr register is ignored) a = 1 : ram bank is specified by bsr register bbb bit address within an 8-bit file register (0 to 7). bsr bank select register. used to select the current ram bank. c, dc, z, ov, n alu status bits: c arry, d igit c arry, z ero, ov erflow, n egative. d destination select bit d = 0 : store result in wreg d = 1 : store result in file register f dest destination: either the wreg register or the specified register file location. f 8-bit register file address (00h to ffh) or 2-bit fsr designator (0h to 3h). f s 12-bit register file address (000h to ff fh). this is the source address. f d 12-bit register file address (000h to fffh). this is the destination address. gie global interrupt enable bit. k literal field, constant data or label (may be either an 8-bit, 12-bit or a 20-bit value). label label name. mm the mode of the tblptr register for the table read and table write instructions. only used with table read and table write instructions: * no change to register (such as tblptr with table reads and writes) *+ post-increment register (such as tblptr with table reads and writes) *- post-decrement register (such as tblptr with table reads and writes) +* pre-increment register (such as tb lptr with table reads and writes) n the relative address (2?s complement number) for relative branch instructions or the direct address for call/branch and return instructions. pc program counter. pcl program counter low byte. pch program counter high byte. pclath program counter high byte latch. pclatu program counter upper byte latch. pd power-down bit. prodh product of multiply high byte. prodl product of multiply low byte. s fast call/return mode select bit s = 0 : do not update into/from shadow registers s = 1 : certain registers loaded into/from shadow registers (fast mode) tblptr 21-bit table pointer (points to a program memory location). tablat 8-bit table latch. to time-out bit. tos top-of-stack. u unused or unchanged. wdt watchdog timer. wreg working register (accumulator). x don?t care (? 0 ? or ? 1 ?). the assembler will generate code with x = 0 . it is the recommended form of use for compatibility with all microchip software tools. z s 7-bit offset value for indirect addr essing of register files (source). z d 7-bit offset value for indirect addressing of register files (destination). { } optional argument. [text] indicates an indexed address. (text) the contents of text . [expr] specifies bit n of the register indicated by the pointer expr . assigned to. < > register bit field. in the set of. italics user-defined term (font is courier new).
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 209 figure 21-1: general format for instructions byte-oriented file register operations 15 10 9 8 7 0 d = 0 for result destination to be wreg register opcode d a f (file #) d = 1 for result destination to be file register (f) a = 0 to force access bank bit-oriented file register operations 15 12 11 9 8 7 0 opcode b (bit #) a f (file #) b = 3-bit position of bit in file register (f) literal operations 15 8 7 0 opcode k (literal) k = 8-bit immediate value byte to byte move operations (2-word) 15 12 11 0 opcode f (source file #) call , goto and branch operations 15 8 7 0 opcode n<7:0> (literal) n = 20-bit immediate value a = 1 for bsr to select bank f = 8-bit file register address a = 0 to force access bank a = 1 for bsr to select bank f = 8-bit file register address 15 12 11 0 1111 n<19:8> (literal) 15 12 11 0 1111 f (destination file #) f = 12-bit file register address control operations example instruction addwf myreg, w, b movff myreg1, myreg2 bsf myreg, bit, b movlw 7fh goto label 15 8 7 0 opcode n<7:0> (literal) 15 12 11 0 1111 n<19:8> (literal) call myfunc 15 11 10 0 opcode n<10:0> (literal) s = fast bit bra myfunc 15 8 7 0 opcode n<7:0> (literal) bc myfunc s
pic18f1230/1330 ds39758b-page 210 advance information ? 2006 microchip technology inc. table 21-2: pic18fxxxx instruction set mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb byte-oriented operations addwf addwfc andwf clrf comf cpfseq cpfsgt cpfslt decf decfsz dcfsnz incf incfsz infsnz iorwf movf movff movwf mulwf negf rlcf rlncf rrcf rrncf setf subfwb subwf subwfb swapf tstfsz xorwf f, d, a f, d, a f, d, a f, a f, d, a f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f, d, a f s , f d f, a f, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a f, d, a f, d, a f, d, a f, a f, d, a add wreg and f add wreg and carry bit to f and wreg with f clear f complement f compare f with wreg, skip = compare f with wreg, skip > compare f with wreg, skip < decrement f decrement f, skip if 0 decrement f, skip if not 0 increment f increment f, skip if 0 increment f, skip if not 0 inclusive or wreg with f move f move f s (source) to 1st word f d (destination) 2nd word move wreg to f multiply wreg with f negate f rotate left f through carry rotate left f (no carry) rotate right f through carry rotate right f (no carry) set f subtract f from wreg with borrow subtract wreg from f subtract wreg from f with borrow swap nibbles in f test f, skip if 0 exclusive or wreg with f 1 1 1 1 1 1 (2 or 3) 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 (2 or 3) 1 (2 or 3) 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 (2 or 3) 1 0010 0010 0001 0110 0001 0110 0110 0110 0000 0010 0100 0010 0011 0100 0001 0101 1100 1111 0110 0000 0110 0011 0100 0011 0100 0110 0101 0101 0101 0011 0110 0001 01da0 0da 01da 101a 11da 001a 010a 000a 01da 11da 11da 10da 11da 10da 00da 00da ffff ffff 111a 001a 110a 01da 01da 00da 00da 100a 01da 11da 10da 10da 011a 10da ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff c, dc, z, ov, n c, dc, z, ov, n z, n z z, n none none none c, dc, z, ov, n none none c, dc, z, ov, n none none z, n z, n none none none c, dc, z, ov, n c, z, n z, n c, z, n z, n none c, dc, z, ov, n c, dc, z, ov, n c, dc, z, ov, n none none z, n 1, 2 1, 2 1,2 2 1, 2 4 4 1, 2 1, 2, 3, 4 1, 2, 3, 4 1, 2 1, 2, 3, 4 4 1, 2 1, 2 1 1, 2 1, 2 1, 2 1, 2 4 1, 2 note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as i nput and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, ?d? = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the se cond word of these instru ctions will be executed as a nop unless the first word of the instruction retrieves the information embe dded in these 16 bits. this ensur es that all program memory locations have a valid instruction.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 211 bit-oriented operations bcf bsf btfsc btfss btg f, b, a f, b, a f, b, a f, b, a f, d, a bit clear f bit set f bit test f, skip if clear bit test f, skip if set bit toggle f 1 1 1 (2 or 3) 1 (2 or 3) 1 1001 1000 1011 1010 0111 bbba bbba bbba bbba bbba ffff ffff ffff ffff ffff ffff ffff ffff ffff ffff none none none none none 1, 2 1, 2 3, 4 3, 4 1, 2 control operations bc bn bnc bnn bnov bnz bov bra bz call clrwdt daw goto nop nop pop push rcall reset retfie retlw return sleep n n n n n n n n n n, s ? ? n ? ? ? ? n s k s ? branch if carry branch if negative branch if not carry branch if not negative branch if not overflow branch if not zero branch if overflow branch unconditionally branch if zero call subroutine 1st word 2nd word clear watchdog timer decimal adjust wreg go to address 1st word 2nd word no operation no operation pop top of return stack (tos) push top of return stack (tos) relative call software device reset return from interrupt enable return with literal in wreg return from subroutine go into standby mode 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 1 (2) 2 1 (2) 2 1 1 2 1 1 1 1 2 1 2 2 2 1 1110 1110 1110 1110 1110 1110 1110 1101 1110 1110 1111 0000 0000 1110 1111 0000 1111 0000 0000 1101 0000 0000 0000 0000 0000 0010 0110 0011 0111 0101 0001 0100 0nnn 0000 110s kkkk 0000 0000 1111 kkkk 0000 xxxx 0000 0000 1nnn 0000 0000 1100 0000 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0000 0000 kkkk kkkk 0000 xxxx 0000 0000 nnnn 1111 0001 kkkk 0001 0000 nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn nnnn kkkk kkkk 0100 0111 kkkk kkkk 0000 xxxx 0110 0101 nnnn 1111 000s kkkk 001s 0011 none none none none none none none none none none to , pd c none none none none none none all gie/gieh, peie/giel none none to , pd 4 table 21-2: pic18fxxxx instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as i nput and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, ?d? = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the se cond word of these instru ctions will be executed as a nop unless the first word of the instruction retrieves the information embe dded in these 16 bits. this ensur es that all program memory locations have a valid instruction.
pic18f1230/1330 ds39758b-page 212 advance information ? 2006 microchip technology inc. literal operations addlw andlw iorlw lfsr movlb movlw mullw retlw sublw xorlw k k k f, k k k k k k k add literal and wreg and literal with wreg inclusive or literal with wreg move literal (12-bit) 2nd word to fsr(f) 1st word move literal to bsr<3:0> move literal to wreg multiply literal with wreg return with literal in wreg subtract wreg from literal exclusive or literal with wreg 1 1 1 2 1 1 1 2 1 1 0000 0000 0000 1110 1111 0000 0000 0000 0000 0000 0000 1111 1011 1001 1110 0000 0001 1110 1101 1100 1000 1010 kkkk kkkk kkkk 00ff kkkk 0000 kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk kkkk c, dc, z, ov, n z, n z, n none none none none none c, dc, z, ov, n z, n data memory ? program memory operations tblrd* tblrd*+ tblrd*- tblrd+* tblwt* tblwt*+ tblwt*- tblwt+* table read table read with post-increment table read with post-decrement table read with pre-increment table write table write with post-increment table write with post-decrement table write with pre-increment 2 2 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 1000 1001 1010 1011 1100 1101 1110 1111 none none none none none none none none table 21-2: pic18fxxxx instruction set (continued) mnemonic, operands description cycles 16-bit instruction word status affected notes msb lsb note 1: when a port register is modified as a function of itself (e.g., movf portb, 1, 0 ), the value used will be that value present on the pins themselves. for example, if the data latch is ? 1 ? for a pin configured as i nput and is driven low by an external device, the data will be written back with a ? 0 ?. 2: if this instruction is executed on the tmr0 register (and where applicable, ?d? = 1 ), the prescaler will be cleared if assigned. 3: if the program counter (pc) is modified or a conditional test is true, the instruction requires two cycles. the second cycle is executed as a nop . 4: some instructions are two-word instructions. the se cond word of these instru ctions will be executed as a nop unless the first word of the instruction retrieves the information embe dded in these 16 bits. this ensur es that all program memory locations have a valid instruction.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 213 21.1.1 standard instruction set addlw add literal to w syntax: addlw k operands: 0 k 255 operation: (w) + k w status affected: n, ov, c, dc, z encoding: 0000 1111 kkkk kkkk description: the contents of w are added to the 8-bit literal ?k? and the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: addlw 15h before instruction w = 10h after instruction w = 25h addwf add w to f syntax: addwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) dest status affected: n, ov, c, dc, z encoding: 0010 01da ffff ffff description: add w to register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwf reg, 0, 0 before instruction w = 17h reg = 0c2h after instruction w = 0d9h reg = 0c2h note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction format then becomes: {label} instruction argument(s).
pic18f1230/1330 ds39758b-page 214 advance information ? 2006 microchip technology inc. addwfc add w and carry bit to f syntax: addwfc f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) + (f) + (c) dest status affected: n,ov, c, dc, z encoding: 0010 00da ffff ffff description: add w, the carry flag and data memory location ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: addwfc reg, 0, 1 before instruction carry bit = 1 reg = 02h w=4dh after instruction carry bit = 0 reg = 02h w = 50h andlw and literal with w syntax: andlw k operands: 0 k 255 operation: (w) .and. k w status affected: n, z encoding: 0000 1011 kkkk kkkk description: the contents of w are anded with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: andlw 05fh before instruction w=a3h after instruction w = 03h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 215 andwf and w with f syntax: andwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .and. (f) dest status affected: n, z encoding: 0001 01da ffff ffff description: the contents of w are anded with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: andwf reg, 0, 0 before instruction w = 17h reg = c2h after instruction w = 02h reg = c2h bc branch if carry syntax: bc n operands: -128 n 127 operation: if carry bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0010 nnnn nnnn description: if the carry bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bc 5 before instruction pc = address (here) after instruction if carry = 1; pc = address (here + 12) if carry = 0; pc = address (here + 2)
pic18f1230/1330 ds39758b-page 216 advance information ? 2006 microchip technology inc. bcf bit clear f syntax: bcf f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: 0 f status affected: none encoding: 1001 bbba ffff ffff description: bit ?b? in register ?f? is cleared. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bcf flag_reg, 7, 0 before instruction flag_reg = c7h after instruction flag_reg = 47h bn branch if negative syntax: bn n operands: -128 n 127 operation: if negative bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0110 nnnn nnnn description: if the negative bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bn jump before instruction pc = address (here) after instruction if negative = 1; pc = address (jump) if negative = 0; pc = address (here + 2)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 217 bnc branch if not carry syntax: bnc n operands: -128 n 127 operation: if carry bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0011 nnnn nnnn description: if the carry bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnc jump before instruction pc = address (here) after instruction if carry = 0; pc = address (jump) if carry = 1; pc = address (here + 2) bnn branch if not negative syntax: bnn n operands: -128 n 127 operation: if negative bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0111 nnnn nnnn description: if the negative bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnn jump before instruction pc = address (here) after instruction if negative = 0; pc = address (jump) if negative = 1; pc = address (here + 2)
pic18f1230/1330 ds39758b-page 218 advance information ? 2006 microchip technology inc. bnov branch if not overflow syntax: bnov n operands: -128 n 127 operation: if overflow bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0101 nnnn nnnn description: if the overflow bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnov jump before instruction pc = address (here) after instruction if overflow = 0; pc = address (jump) if overflow = 1; pc = address (here + 2) bnz branch if not zero syntax: bnz n operands: -128 n 127 operation: if zero bit is ? 0 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0001 nnnn nnnn description: if the zero bit is ? 0 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bnz jump before instruction pc = address (here) after instruction if zero = 0; pc = address (jump) if zero = 1; pc = address (here + 2)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 219 bra unconditional branch syntax: bra n operands: -1024 n 1023 operation: (pc) + 2 + 2n pc status affected: none encoding: 1101 0nnn nnnn nnnn description: add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation example: here bra jump before instruction pc = address (here) after instruction pc = address (jump) bsf bit set f syntax: bsf f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: 1 f status affected: none encoding: 1000 bbba ffff ffff description: bit ?b? in register ?f? is set. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: bsf flag_reg, 7, 1 before instruction flag_reg = 0ah after instruction flag_reg = 8ah
pic18f1230/1330 ds39758b-page 220 advance information ? 2006 microchip technology inc. btfsc bit test file, skip if clear syntax: btfsc f, b {,a} operands: 0 f 255 0 b 7 a [0,1] operation: skip if (f) = 0 status affected: none encoding: 1011 bbba ffff ffff description: if bit ?b? in register ?f? is ? 0 ?, then the next instruction is skipped. if bit ?b? is ? 0 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfsc : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (true) if flag<1> = 1; pc = address (false) btfss bit test file, skip if set syntax: btfss f, b {,a} operands: 0 f 255 0 b < 7 a [0,1] operation: skip if (f) = 1 status affected: none encoding: 1010 bbba ffff ffff description: if bit ?b? in register ?f? is ? 1 ?, then the next instruction is skipped. if bit ?b? is ? 1 ?, then the next instruction fetched during the current instruction execution is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here false true btfss : : flag, 1, 0 before instruction pc = address (here) after instruction if flag<1> = 0; pc = address (false) if flag<1> = 1; pc = address (true)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 221 btg bit toggle f syntax: btg f, b {,a} operands: 0 f 255 0 b < 7 a [0,1] operation: (f ) f status affected: none encoding: 0111 bbba ffff ffff description: bit ?b? in data memory location ?f? is inverted. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: btg portc, 4, 0 before instruction: portc = 0111 0101 [75h] after instruction: portc = 0110 0101 [65h] bov branch if overflow syntax: bov n operands: -128 n 127 operation: if overflow bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0100 nnnn nnnn description: if the overflow bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bov jump before instruction pc = address (here) after instruction if overflow = 1; pc = address (jump) if overflow = 0; pc = address (here + 2)
pic18f1230/1330 ds39758b-page 222 advance information ? 2006 microchip technology inc. bz branch if zero syntax: bz n operands: -128 n 127 operation: if zero bit is ? 1 ? (pc) + 2 + 2n pc status affected: none encoding: 1110 0000 nnnn nnnn description: if the zero bit is ? 1 ?, then the program will branch. the 2?s complement number ?2n? is added to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is then a two-cycle instruction. words: 1 cycles: 1(2) q cycle activity: if jump: q1 q2 q3 q4 decode read literal ?n? process data write to pc no operation no operation no operation no operation if no jump: q1 q2 q3 q4 decode read literal ?n? process data no operation example: here bz jump before instruction pc = address (here) after instruction if zero = 1; pc = address (jump) if zero = 0; pc = address (here + 2) call subroutine call syntax: call k {,s} operands: 0 k 1048575 s [0,1] operation: (pc) + 4 tos, k pc<20:1> if s = 1 (w) ws, (status) statuss, (bsr) bsrs status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 110s k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: subroutine call of entire 2-mbyte memory range. first, return address (pc + 4) is pushed onto the return stack. if ?s? = 1 , the w, status and bsr registers are also pushed into their respective shadow registers, ws, statuss and bsrs. if ?s? = 0 , no update occurs (default). then, the 20-bit value ?k? is loaded into pc<20:1>. call is a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, push pc to stack read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: here call there, 1 before instruction pc = address (here) after instruction pc = address (there) tos = address (here + 4) ws = w bsrs = bsr statuss = status
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 223 clrf clear f syntax: clrf f {,a} operands: 0 f 255 a [0,1] operation: 000h f, 1 z status affected: z encoding: 0110 101a ffff ffff description: clears the contents of the specified register. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: clrf flag_reg, 1 before instruction flag_reg = 5ah after instruction flag_reg = 00h clrwdt clear watchdog timer syntax: clrwdt operands: none operation: 000h wdt, 000h wdt postscaler, 1 to, 1 pd status affected: to , pd encoding: 0000 0000 0000 0100 description: clrwdt instruction resets the watchdog timer. it also resets the postscaler of the wdt. status bits, to and pd , are set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data no operation example: clrwdt before instruction wdt counter = ? after instruction wdt counter = 00h wdt postscaler = 0 to =1 pd =1
pic18f1230/1330 ds39758b-page 224 advance information ? 2006 microchip technology inc. comf complement f syntax: comf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f ) dest status affected: n, z encoding: 0001 11da ffff ffff description: the contents of register ?f? are complemented. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: comf reg, 0, 0 before instruction reg = 13h after instruction reg = 13h w=ech cpfseq compare f with w, skip if f = w syntax: cpfseq f {,a} operands: 0 f 255 a [0,1] operation: (f) ? (w), skip if (f) = (w) (unsigned comparison) status affected: none encoding: 0110 001a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if ?f? = w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfseq reg, 0 nequal : equal : before instruction pc address = here w=? reg = ? after instruction if reg = w; pc = address (equal) if reg w; pc = address (nequal)
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 225 cpfsgt compare f with w, skip if f > w syntax: cpfsgt f {,a} operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) > (w) (unsigned comparison) status affected: none encoding: 0110 010a ffff ffff description: compares the contents of data memory location ?f? to the contents of the w by performing an unsigned subtraction. if the contents of ?f? are greater than the contents of wreg , then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfsgt reg, 0 ngreater : greater : before instruction pc = address (here) w= ? after instruction if reg > w; pc = address (greater) if reg w; pc = address (ngreater) cpfslt compare f with w, skip if f < w syntax: cpfslt f {,a} operands: 0 f 255 a [0,1] operation: (f) ? ( w), skip if (f) < (w) (unsigned comparison) status affected: none encoding: 0110 000a ffff ffff description: compares the contents of data memory location ?f? to the contents of w by performing an unsigned subtraction. if the contents of ?f? are less than the contents of w, then the fetched instruction is discarded and a nop is executed instead, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here cpfslt reg, 1 nless : less : before instruction pc = address (here) w= ? after instruction if reg < w; pc = address (less) if reg w; pc = address (nless)
pic18f1230/1330 ds39758b-page 226 advance information ? 2006 microchip technology inc. daw decimal adjust w register syntax: daw operands: none operation: if [w<3:0> > 9] or [dc = 1 ] then (w<3:0>) + 6 w<3:0>; else ( w<3:0>) w<3:0> if [w<7:4> + dc > 9] or [c = 1 ] then ( w<7:4>) + 6 + dc w<7:4> ; else (w<7:4>) + dc w<7:4> status affected: c encoding: 0000 0000 0000 0111 description: daw adjusts the eight-bit value in w resulting from the earlier addition of two variables (each in packed bcd format) and produces a correct packed bcd result. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register w process data write w example 1: daw before instruction w=a5h c=0 dc = 0 after instruction w = 05h c=1 dc = 0 example 2: before instruction w=ceh c=0 dc = 0 after instruction w = 34h c=1 dc = 0 decf decrement f syntax: decf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest status affected: c, dc, n, ov, z encoding: 0000 01da ffff ffff description: decrement register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: decf cnt, 1, 0 before instruction cnt = 01h z=0 after instruction cnt = 00h z=1
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 227 decfsz decrement f, skip if 0 syntax: decfsz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result = 0 status affected: none encoding: 0010 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruction, which is already fetched, is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here decfsz cnt, 1, 1 goto loop continue before instruction pc = address (here) after instruction cnt = cnt ? 1 if cnt = 0; pc = address (continue) if cnt 0; pc = address (here + 2) dcfsnz decrement f, skip if not 0 syntax: dcfsnz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? 1 dest, skip if result 0 status affected: none encoding: 0100 11da ffff ffff description: the contents of register ?f? are decremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction, which is already fetched, is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here dcfsnz temp, 1, 0 zero : nzero : before instruction temp = ? after instruction temp = temp ? 1 if temp = 0; pc = address (zero) if temp 0; pc = address (nzero)
pic18f1230/1330 ds39758b-page 228 advance information ? 2006 microchip technology inc. goto unconditional branch syntax: goto k operands: 0 k 1048575 operation: k pc<20:1> status affected: none encoding: 1st word (k<7:0>) 2nd word(k<19:8>) 1110 1111 1111 k 19 kkk k 7 kkk kkkk kkkk 0 kkkk 8 description: goto allows an unconditional branch anywhere within entire 2-mbyte memory range. the 20-bit value ?k? is loaded into pc<20:1>. goto is always a two-cycle instruction. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k?<7:0>, no operation read literal ?k?<19:8>, write to pc no operation no operation no operation no operation example: goto there after instruction pc = address (there) incf increment f syntax: incf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest status affected: c, dc, n, ov, z encoding: 0010 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: incf cnt, 1, 0 before instruction cnt = ffh z=0 c=? dc = ? after instruction cnt = 00h z=1 c=1 dc = 1
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 229 incfsz increment f, skip if 0 syntax: incfsz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result = 0 status affected: none encoding: 0011 11da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is ? 0 ?, the next instruction, which is already fetched, is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here incfsz cnt, 1, 0 nzero : zero : before instruction pc = address (here) after instruction cnt = cnt + 1 if cnt = 0; pc = address (zero) if cnt 0; pc = address (nzero) infsnz increment f, skip if not 0 syntax: infsnz f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) + 1 dest, skip if result 0 status affected: none encoding: 0100 10da ffff ffff description: the contents of register ?f? are incremented. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if the result is not ? 0 ?, the next instruction, which is already fetched, is discarded and a nop is executed instead, making it a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here infsnz reg, 1, 0 zero nzero before instruction pc = address (here) after instruction reg = reg + 1 if reg 0; pc = address (nzero) if reg = 0; pc = address (zero)
pic18f1230/1330 ds39758b-page 230 advance information ? 2006 microchip technology inc. iorlw inclusive or literal with w syntax: iorlw k operands: 0 k 255 operation: (w) .or. k w status affected: n, z encoding: 0000 1001 kkkk kkkk description: the contents of w are ored with the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: iorlw 35h before instruction w=9ah after instruction w=bfh iorwf inclusive or w with f syntax: iorwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .or. (f) dest status affected: n, z encoding: 0001 00da ffff ffff description: inclusive or w with register ?f?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: iorwf result, 0, 1 before instruction result = 13h w = 91h after instruction result = 13h w = 93h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 231 lfsr load fsr syntax: lfsr f, k operands: 0 f 2 0 k 4095 operation: k fsrf status affected: none encoding: 1110 1111 1110 0000 00ff k 7 kkk k 11 kkk kkkk description: the 12-bit literal ?k? is loaded into the file select register pointed to by ?f?. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? msb process data write literal ?k? msb to fsrfh decode read literal ?k? lsb process data write literal ?k? to fsrfl example: lfsr 2, 3abh after instruction fsr2h = 03h fsr2l = abh movf move f syntax: movf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: f dest status affected: n, z encoding: 0101 00da ffff ffff description: the contents of register ?f? are moved to a destination dependent upon the status of ?d?. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write w example: movf reg, 0, 0 before instruction reg = 22h w=ffh after instruction reg = 22h w = 22h
pic18f1230/1330 ds39758b-page 232 advance information ? 2006 microchip technology inc. movff move f to f syntax: movff f s ,f d operands: 0 f s 4095 0 f d 4095 operation: (f s ) f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1100 1111 ffff ffff ffff ffff fff f s fff f d description: the contents of source register ?f s ? are moved to destination register ?f d ?. location of source ?f s ? can be anywhere in the 4096-byte data space (000h to fffh) and location of destination ?f d ? can also be anywhere from 000h to fffh. either source or destination can be w (a useful special situation). movff is particularly useful for transferring a data memory location to a peripheral register (such as the transmit buffer or an i/o port). the movff instruction cannot use the pcl, tosu, tosh or tosl as the destination register. words: 2 cycles: 2 (3) q cycle activity: q1 q2 q3 q4 decode read register ?f? (src) process data no operation decode no operation no dummy read no operation write register ?f? (dest) example: movff reg1, reg2 before instruction reg1 = 33h reg2 = 11h after instruction reg1 = 33h reg2 = 33h movlb move literal to low nibble in bsr syntax: movlw k operands: 0 k 255 operation: k bsr status affected: none encoding: 0000 0001 kkkk kkkk description: the eight-bit literal ?k? is loaded into the bank select register (bsr). the value of bsr<7:4> always remains ? 0 ?, regardless of the value of k 7 :k 4 . words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write literal ?k? to bsr example: movlb 5 before instruction bsr register = 02h after instruction bsr register = 05h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 233 movlw move literal to w syntax: movlw k operands: 0 k 255 operation: k w status affected: none encoding: 0000 1110 kkkk kkkk description: the eight-bit literal ?k? is loaded into w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: movlw 5ah after instruction w=5ah movwf move w to f syntax: movwf f {,a} operands: 0 f 255 a [0,1] operation: (w) f status affected: none encoding: 0110 111a ffff ffff description: move data from w to register ?f?. location ?f? can be anywhere in the 256-byte bank. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: movwf reg, 0 before instruction w=4fh reg = ffh after instruction w=4fh reg = 4fh
pic18f1230/1330 ds39758b-page 234 advance information ? 2006 microchip technology inc. mullw multiply literal with w syntax: mullw k operands: 0 k 255 operation: (w) x k prodh:prodl status affected: none encoding: 0000 1101 kkkk kkkk description: an unsigned multiplication is carried out between the contents of w and the 8-bit literal ?k?. the 16-bit result is placed in the prodh:prodl register pair. prodh contains the high byte. w is unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write registers prodh: prodl example: mullw 0c4h before instruction w=e2h prodh = ? prodl = ? after instruction w=e2h prodh = adh prodl = 08h mulwf multiply w with f syntax: mulwf f {,a} operands: 0 f 255 a [0,1] operation: (w) x (f) prodh:prodl status affected: none encoding: 0000 001a ffff ffff description: an unsigned multiplication is carried out between the contents of w and the register file location ?f?. the 16-bit result is stored in the prodh:prodl register pair. prodh contains the high byte. both w and ?f? are unchanged. none of the status flags are affected. note that neither overflow nor carry is possible in this operation. a zero result is possible but not detected. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write registers prodh: prodl example: mulwf reg, 1 before instruction w=c4h reg = b5h prodh = ? prodl = ? after instruction w=c4h reg = b5h prodh = 8ah prodl = 94h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 235 negf negate f syntax: negf f {,a} operands: 0 f 255 a [0,1] operation: (f ) + 1 f status affected: n, ov, c, dc, z encoding: 0110 110a ffff ffff description: location ?f? is negated using two?s complement. the result is placed in the data memory location ?f?. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: negf reg, 1 before instruction reg = 0011 1010 [3ah] after instruction reg = 1100 0110 [c6h] nop no operation syntax: nop operands: none operation: no operation status affected: none encoding: 0000 1111 0000 xxxx 0000 xxxx 0000 xxxx description: no operation. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation example: none.
pic18f1230/1330 ds39758b-page 236 advance information ? 2006 microchip technology inc. pop pop top of return stack syntax: pop operands: none operation: (tos) bit bucket status affected: none encoding: 0000 0000 0000 0110 description: the tos value is pulled off the return stack and is discarded. the tos value then becomes the previous value that was pushed onto the return stack. this instruction is provided to enable the user to properly manage the return stack to incorporate a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation pop tos value no operation example: pop goto new before instruction tos = 0031a2h stack (1 level down) = 014332h after instruction tos = 014332h pc = new push push top of return stack syntax: push operands: none operation: (pc + 2) tos status affected: none encoding: 0000 0000 0000 0101 description: the pc + 2 is pushed onto the top of the return stack. the previous tos value is pushed down on the stack. this instruction allows implementing a software stack by modifying tos and then pushing it onto the return stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode push pc + 2 onto return stack no operation no operation example: push before instruction tos = 345ah pc = 0124h after instruction pc = 0126h tos = 0126h stack (1 level down) = 345ah
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 237 rcall relative call syntax: rcall n operands: -1024 n 1023 operation: (pc) + 2 tos, (pc) + 2 + 2n pc status affected: none encoding: 1101 1nnn nnnn nnnn description: subroutine call with a jump up to 1k from the current location. first, return address (pc + 2) is pushed onto the stack. then, add the 2?s complement number ?2n? to the pc. since the pc will have incremented to fetch the next instruction, the new address will be pc + 2 + 2n. this instruction is a two-cycle instruction. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?n? push pc to stack process data write to pc no operation no operation no operation no operation example: here rcall jump before instruction pc = address (here) after instruction pc = address (jump) tos = address (here + 2) reset reset syntax: reset operands: none operation: reset all registers and flags that are affected by a mclr reset. status affected: all encoding: 0000 0000 1111 1111 description: this instruction provides a way to execute a mclr reset in software. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode start reset no operation no operation example: reset after instruction registers = reset value flags* = reset value
pic18f1230/1330 ds39758b-page 238 advance information ? 2006 microchip technology inc. retfie return from interrupt syntax: retfie {s} operands: s [0,1] operation: (tos) pc, 1 gie/gieh or peie/giel if s = 1 (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged status affected: gie/gieh, peie/giel encoding: 0000 0000 0001 000s description: return from interrupt. stack is popped and top-of-stack (tos) is loaded into the pc. interrupts are enabled by setting either the high or low priority global interrupt enable bit. if ?s? = 1 , the contents of the shadow registers, ws, statuss and bsrs, are loaded into their corresponding registers, w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation pop pc from stack set gieh or giel no operation no operation no operation no operation example: retfie 1 after interrupt pc = tos w=ws bsr = bsrs status = statuss gie/gieh, peie/giel = 1 retlw return literal to w syntax: retlw k operands: 0 k 255 operation: k w, (tos) pc, pclatu, pclath are unchanged status affected: none encoding: 0000 1100 kkkk kkkk description: w is loaded with the eight-bit literal ?k?. the program counter is loaded from the top of the stack (the return address). the high address latch (pclath) remains unchanged. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data pop pc from stack, write to w no operation no operation no operation no operation example: call table ; w contains table ; offset value ; w now has ; table value : table addwf pcl ; w = offset retlw k0 ; begin table retlw k1 ; : : retlw kn ; end of table before instruction w = 07h after instruction w = value of kn
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 239 return return from subroutine syntax: return {s} operands: s [0,1] operation: (tos) pc if s = 1 (ws) w, (statuss) status, (bsrs) bsr, pclatu, pclath are unchanged status affected: none encoding: 0000 0000 0001 001s description: return from subroutine. the stack is popped and the top of the stack (tos) is loaded into the program counter. if ?s?= 1 , the contents of the shadow registers, ws, statuss and bsrs, are loaded into their corresponding registers, w, status and bsr. if ?s? = 0 , no update of these registers occurs (default). words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation process data pop pc from stack no operation no operation no operation no operation example: return after instruction: pc = tos rlcf rotate left f through carry syntax: rlcf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) c, (c) dest<0> status affected: c, n, z encoding: 0011 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 1100 1100 c=1 c register f
pic18f1230/1330 ds39758b-page 240 advance information ? 2006 microchip technology inc. rlncf rotate left f (no carry) syntax: rlncf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<7>) dest<0> status affected: n, z encoding: 0100 01da ffff ffff description: the contents of register ?f? are rotated one bit to the left. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rlncf reg, 1, 0 before instruction reg = 1010 1011 after instruction reg = 0101 0111 register f rrcf rotate right f through carry syntax: rrcf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) c, (c) dest<7> status affected: c, n, z encoding: 0011 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right through the carry flag. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: rrcf reg, 0, 0 before instruction reg = 1110 0110 c=0 after instruction reg = 1110 0110 w= 0111 0011 c=0 c register f
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 241 rrncf rotate right f (no carry) syntax: rrncf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) dest, (f<0>) dest<7> status affected: n, z encoding: 0100 00da ffff ffff description: the contents of register ?f? are rotated one bit to the right. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed back in register ?f? (default). if ?a? is ? 0 ?, the access bank will be selected, overriding the bsr value. if ?a? is ? 1 ?, then the bank will be selected as per the bsr value (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: rrncf reg, 1, 0 before instruction reg = 1101 0111 after instruction reg = 1110 1011 example 2: rrncf reg, 0, 0 before instruction w=? reg = 1101 0111 after instruction w= 1110 1011 reg = 1101 0111 register f setf set f syntax: setf f {,a} operands: 0 f 255 a [0,1] operation: ffh f status affected: none encoding: 0110 100a ffff ffff description: the contents of the specified register are set to ffh. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write register ?f? example: setf reg, 1 before instruction reg = 5ah after instruction reg = ffh
pic18f1230/1330 ds39758b-page 242 advance information ? 2006 microchip technology inc. sleep enter sleep mode syntax: sleep operands: none operation: 00h wdt, 0 wdt postscaler, 1 to , 0 pd status affected: to , pd encoding: 0000 0000 0000 0011 description: the power-down status bit (pd ) is cleared. the time-out status bit (to ) is set. watchdog timer and its postscaler are cleared. the processor is put into sleep mode with the oscillator stopped. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode no operation process data go to sleep example: sleep before instruction to =? pd =? after instruction to =1? pd =0 ? if wdt causes wake-up, this bit is cleared. subfwb subtract f from w with borrow syntax: subfwb f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) ? (f) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 01da ffff ffff description: subtract register ?f? and carry flag (borrow) from w (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subfwb reg, 1, 0 before instruction reg = 3 w=2 c=1 after instruction reg = ff w=2 c=0 z=0 n = 1 ; result is negative example 2: subfwb reg, 0, 0 before instruction reg = 2 w=5 c=1 after instruction reg = 2 w=3 c=1 z=0 n = 0 ; result is positive example 3: subfwb reg, 1, 0 before instruction reg = 1 w=2 c=0 after instruction reg = 0 w=2 c=1 z = 1 ; result is zero n=0
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 243 sublw subtract w from literal syntax: sublw k operands: 0 k 255 operation: k ? (w) w status affected: n, ov, c, dc, z encoding: 0000 1000 kkkk kkkk description w is subtracted from the eight-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example 1: sublw 02h before instruction w = 01h c=? after instruction w = 01h c = 1 ; result is positive z=0 n=0 example 2: sublw 02h before instruction w = 02h c=? after instruction w = 00h c = 1 ; result is zero z=1 n=0 example 3: sublw 02h before instruction w = 03h c=? after instruction w = ffh ; (2?s complement) c = 0 ; result is negative z=0 n=1 subwf subtract w from f syntax: subwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) dest status affected: n, ov, c, dc, z encoding: 0101 11da ffff ffff description: subtract w from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in index ed litera l offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwf reg, 1, 0 before instruction reg = 3 w=2 c=? after instruction reg = 1 w=2 c = 1 ; result is positive z=0 n=0 example 2: subwf reg, 0, 0 before instruction reg = 2 w=2 c=? after instruction reg = 2 w=0 c = 1 ; result is zero z=1 n=0 example 3: subwf reg, 1, 0 before instruction reg = 1 w=2 c=? after instruction reg = ffh ;(2?s complement) w=2 c = 0 ; result is negative z=0 n=1
pic18f1230/1330 ds39758b-page 244 advance information ? 2006 microchip technology inc. subwfb subtract w from f with borrow syntax: subwfb f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f) ? (w) ? (c ) dest status affected: n, ov, c, dc, z encoding: 0101 10da ffff ffff description: subtract w and the carry flag (borrow) from register ?f? (2?s complement method). if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example 1: subwfb reg, 1, 0 before instruction reg = 19h (0001 1001) w=0dh (0000 1101) c=1 after instruction reg = 0ch (0000 1011) w=0dh (0000 1101) c=1 z=0 n = 0 ; result is positive example 2: subwfb reg, 0, 0 before instruction reg = 1bh (0001 1011) w=1ah (0001 1010) c=0 after instruction reg = 1bh (0001 1011) w = 00h c=1 z = 1 ; result is zero n=0 example 3: subwfb reg, 1, 0 before instruction reg = 03h (0000 0011) w=0eh (0000 1101) c=1 after instruction reg = f5h (1111 0100) ; [2?s comp] w=0eh (0000 1101) c=0 z=0 n = 1 ; result is negative swapf swap f syntax: swapf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (f<3:0>) dest<7:4>, (f<7:4>) dest<3:0> status affected: none encoding: 0011 10da ffff ffff description: the upper and lower nibbles of register ?f? are exchanged. if ?d? is ? 0 ?, the result is placed in w. if ?d? is ? 1 ?, the result is placed in register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset a ddressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: swapf reg, 1, 0 before instruction reg = 53h after instruction reg = 35h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 245 tblrd table read syntax: tblrd ( *; *+; *-; +*) operands: none operation: if tblrd * (prog mem (tblptr)) tablat; tblptr ? no change; if tblrd *+ (prog mem (tblptr)) tablat; (tblptr) + 1 tblptr; if tblrd *- (prog mem (tblptr)) tablat; (tblptr) ? 1 tblptr; if tblrd +* (tblptr) + 1 tblptr; (prog mem (tblptr)) tablat status affected: none encoding: 0000 0000 0000 10nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction is used to read the contents of program memory (p.m.). to address the program memory, a pointer called table pointer (tblptr) is used. the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. tblptr[0] = 0 : least significant byte of program memory word tblptr[0] = 1 : most significant byte of program memory word the tblrd instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read program memory) no operation no operation (write tablat) tblrd table read (continued) example 1: tblrd *+ ; before instruction tablat = 55h tblptr = 00a356h memory (00a356h) = 34h after instruction tablat = 34h tblptr = 00a357h example 2: tblrd +* ; before instruction tablat = aah tblptr = 01a357h memory (01a357h) = 12h memory (01a358h) = 34h after instruction tablat = 34h tblptr = 01a358h
pic18f1230/1330 ds39758b-page 246 advance information ? 2006 microchip technology inc. tblwt table write syntax: tblwt ( *; *+; *-; +*) operands: none operation: if tblwt* (tablat) holding register; tblptr ? no change; if tblwt*+ (tablat) holding register; (tblptr) + 1 tblptr; if tblwt*- (tablat) holding register; (tblptr) ? 1 tblptr; if tblwt+* (tblptr) + 1 tblptr; (tablat) holding register status affected: none encoding: 0000 0000 0000 11nn nn=0 * =1 *+ =2 *- =3 +* description: this instruction uses the 3 lsbs of tblptr to determine which of the 8 holding registers the tablat is written to. the holding registers are used to program the contents of program memory (p.m.). (refer to section 6.0 ?flash program memory? for additional details on programming flash memory.) the tblptr (a 21-bit pointer) points to each byte in the program memory. tblptr has a 2-mbyte address range. the lsb of the tblptr selects which byte of the program memory location to access. tblptr[0] = 0 : least significant byte of program memory word tblptr[0] = 1 : most significant byte of program memory word the tblwt instruction can modify the value of tblptr as follows: ? no change ? post-increment ? post-decrement ? pre-increment words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode no operation no operation no operation no operation no operation (read tablat) no operation no operation (write to holding register ) tblwt table write (continued) example 1: tblwt *+; before instruction tablat = 55h tblptr = 00a356h holding register (00a356h) = ffh after instructions (table write completion) tablat = 55h tblptr = 00a357h holding register (00a356h) = 55h example 2: tblwt +*; before instruction tablat = 34h tblptr = 01389ah holding register (01389ah) = ffh holding register (01389bh) = ffh after instruction (table write completion) tablat = 34h tblptr = 01389bh holding register (01389ah) = ffh holding register (01389bh) = 34h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 247 tstfsz test f, skip if 0 syntax: tstfsz f {,a} operands: 0 f 255 a [0,1] operation: skip if f = 0 status affected: none encoding: 0110 011a ffff ffff description: if ?f? = 0 , the next instruction fetched during the current instruction execution is discarded and a nop is executed, making this a two-cycle instruction. if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1(2) note: 3 cycles if skip and followed by a 2-word instruction. q cycle activity: q1 q2 q3 q4 decode read register ?f? process data no operation if skip: q1 q2 q3 q4 no operation no operation no operation no operation if skip and followed by 2-word instruction: q1 q2 q3 q4 no operation no operation no operation no operation no operation no operation no operation no operation example: here tstfsz cnt, 1 nzero : zero : before instruction pc = address (here) after instruction if cnt = 00h, pc = address (zero) if cnt 00h, pc = address (nzero) xorlw exclusive or literal with w syntax: xorlw k operands: 0 k 255 operation: (w) .xor. k w status affected: n, z encoding: 0000 1010 kkkk kkkk description: the contents of w are xored with the 8-bit literal ?k?. the result is placed in w. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to w example: xorlw 0afh before instruction w=b5h after instruction w=1ah
pic18f1230/1330 ds39758b-page 248 advance information ? 2006 microchip technology inc. xorwf exclusive or w with f syntax: xorwf f {,d {,a}} operands: 0 f 255 d [0,1] a [0,1] operation: (w) .xor. (f) dest status affected: n, z encoding: 0001 10da ffff ffff description: exclusive or the contents of w with register ?f?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in the register ?f? (default). if ?a? is ? 0 ?, the access bank is selected. if ?a? is ? 1 ?, the bsr is used to select the gpr bank (default). if ?a? is ? 0 ? and the extended instruction set is enabled, this instruction operates in indexed literal offset addressing mode whenever f 95 (5fh). see section 21.2.3 ?byte-oriented and bit-oriented instructions in indexed literal offset mode? for details. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: xorwf reg, 1, 0 before instruction reg = afh w=b5h after instruction reg = 1ah w=b5h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 249 21.2 extended instruction set in addition to the standard 75 instructions of the pic18 instruction set, pic18f1230/1330 devices also provide an optional extension to the core cpu functionality. the added features include eight additional instruc- tions that augment indirect and indexed addressing operations and the implementation of indexed literal offset addressing mode for many of the standard pic18 instructions. the additional features of the extended instruction set are disabled by default. to enable them, users must set the xinst configuration bit. the instructions in the extended set (with the exception of callw , movsf and movss ) can all be classified as literal operations, which either manipulate the file select registers, or use them for indexed addressing. two of the instructions, addfsr and subfsr , each have an additional special instantiation for using fsr2. these versions ( addulnk and subulnk ) allow for automatic return after execution. the extended instructions are specifically implemented to optimize re-entrant program code (that is, code that is recursive or that uses a software stack) written in high-level languages, particularly c. among other things, they allow users working in high-level languages to perform certain operations on data structures more efficiently. these include: ? dynamic allocation and deallocation of software stack space when entering and leaving subroutines ? function pointer invocation ? software stack pointer manipulation ? manipulation of variables located in a software stack a summary of the instructions in the extended instruction set is provided in table 21-3. detailed descriptions are provided in section 21.2.2 ?extended instruction set? . the opcode field descriptions in table 21-1 (page 208) apply to both the standard and extended pic18 instruction sets. 21.2.1 extended instruction syntax most of the extended instructions use indexed arguments, using one of the file select registers and some offset to specify a source or destination register. when an argument for an instruction serves as part of indexed addressing, it is enclosed in square brackets (?[ ]?). this is done to indicate that the argument is used as an index or offset. the mpasm? assembler will flag an error if it determines that an index or offset value is not bracketed. when the extended instruction set is enabled, brackets are also used to indicate index arguments in byte- oriented and bit-oriented instructions. this is in addition to other changes in their syntax. for more details, see section 21.2.3.1 ?extended instruction syntax with standard pic18 commands? . table 21-3: extensions to the pic18 instruction set note: the instruction set extension and the indexed literal offset addressing mode were designed for optimizing applications written in c; the user may likely never use these instructions directly in the assem- bler. the syntax for these commands is provided as a reference for users who may be reviewing code that has been generated by a compiler. note: in the past, square brackets have been used to denote optional arguments in the pic18 and earlier instruction sets. in this text and going forward, optional arguments are denoted by braces (?{ }?). mnemonic, operands description cycles 16-bit instruction word status affected msb lsb addfsr addulnk callw movsf movss pushl subfsr subulnk f, k k z s , f d z s , z d k f, k k add literal to fsr add literal to fsr2 and return call subroutine using wreg move z s (source) to 1st word f d (destination) 2nd word move z s (source) to 1st word z d (destination) 2nd word store literal at fsr2, decrement fsr2 subtract literal from fsr subtract literal from fsr2 and return 1 2 2 2 2 1 1 2 1110 1110 0000 1110 1111 1110 1111 1110 1110 1110 1000 1000 0000 1011 ffff 1011 xxxx 1010 1001 1001 ffkk 11kk 0001 0zzz ffff 1zzz xzzz kkkk ffkk 11kk kkkk kkkk 0100 zzzz ffff zzzz zzzz kkkk kkkk kkkk none none none none none none none none
pic18f1230/1330 ds39758b-page 250 advance information ? 2006 microchip technology inc. 21.2.2 extended instruction set addfsr add literal to fsr syntax: addfsr f, k operands: 0 k 63 f [ 0, 1, 2 ] operation: fsr(f) + k fsr(f) status affected: none encoding: 1110 1000 ffkk kkkk description: the 6-bit literal ?k? is added to the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr example: addfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 0422h addulnk add literal to fsr2 and return syntax: addulnk k operands: 0 k 63 operation: fsr2 + k fsr2, (tos) pc status affected: none encoding: 1110 1000 11kk kkkk description: the 6-bit literal ?k? is added to the contents of fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the addfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read literal ?k? process data write to fsr no operation no operation no operation no operation example: addulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 0422h pc = (tos) note: all pic18 instructions may take an optional label argument preceding the instruction mnemonic for use in symbolic addressing. if a label is used, the instruction syntax then becomes: {label} instruction argument(s).
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 251 callw subroutine call using wreg syntax: callw operands: none operation: (pc + 2) tos, (w) pcl, (pclath) pch, (pclatu) pcu status affected: none encoding: 0000 0000 0001 0100 description first, the return address (pc + 2) is pushed onto the return stack. next, the contents of w are written to pcl; the existing value is discarded. then, the contents of pclath and pclatu are latched into pch and pcu, respectively. the second cycle is executed as a nop instruction while the new next instruction is fetched. unlike call , there is no option to update w, status or bsr. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read wreg push pc to stack no operation no operation no operation no operation no operation example: here callw before instruction pc = address (here) pclath = 10h pclatu = 00h w = 06h after instruction pc = 001006h tos = address (here + 2) pclath = 10h pclatu = 00h w = 06h movsf move indexed to f syntax: movsf [z s ], f d operands: 0 z s 127 0 f d 4095 operation: ((fsr2) + z s ) f d status affected: none encoding: 1st word (source) 2nd word (destin.) 1110 1111 1011 ffff 0zzz ffff zzzz s ffff d description: the contents of the source register are moved to destination register ?f d ?. the actual address of the source register is determined by adding the 7-bit literal offset ?z s ? in the first word to the value of fsr2. the address of the destination register is specified by the 12-bit literal ?f d ? in the second word. both addresses can be anywhere in the 4096-byte data space (000h to fffh). the movsf instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode no operation no dummy read no operation write register ?f? (dest) example: movsf [05h], reg2 before instruction fsr2 = 80h contents of 85h = 33h reg2 = 11h after instruction fsr2 = 80h contents of 85h = 33h reg2 = 33h
pic18f1230/1330 ds39758b-page 252 advance information ? 2006 microchip technology inc. movss move indexed to indexed syntax: movss [z s ], [z d ] operands: 0 z s 127 0 z d 127 operation: ((fsr2) + z s ) ((fsr2) + z d ) status affected: none encoding: 1st word (source) 2nd word (dest.) 1110 1111 1011 xxxx 1zzz xzzz zzzz s zzzz d description the contents of the source register are moved to the destination register. the addresses of the source and destination registers are determined by adding the 7-bit literal offsets ?z s ? or ?z d ?, respectively, to the value of fsr2. both registers can be located anywhere in the 4096-byte data memory space (000h to fffh). the movss instruction cannot use the pcl, tosu, tosh or tosl as the destination register. if the resultant source address points to an indirect addressing register, the value returned will be 00h. if the resultant destination address points to an indirect addressing register, the instruction will execute as a nop . words: 2 cycles: 2 q cycle activity: q1 q2 q3 q4 decode determine source addr determine source addr read source reg decode determine dest addr determine dest addr write to dest reg example: movss [05h], [06h] before instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 11h after instruction fsr2 = 80h contents of 85h = 33h contents of 86h = 33h pushl store literal at fsr2, decrement fsr2 syntax: pushl k operands: 0 k 255 operation: k (fsr2), fsr2 ? 1 fsr2 status affected: none encoding: 1111 1010 kkkk kkkk description: the 8-bit literal ?k? is written to the data memory address specified by fsr2. fsr2 is decremented by 1 after the operation. this instruction allows users to push values onto a software stack. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: pushl 08h before instruction fsr2h:fsr2l = 01ech memory (01ech) = 00h after instruction fsr2h:fsr2l = 01ebh memory (01ech) = 08h
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 253 subfsr subtract literal from fsr syntax: subfsr f, k operands: 0 k 63 f [ 0, 1, 2 ] operation: fsr(f ? k) fsr(f) status affected: none encoding: 1110 1001 ffkk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr specified by ?f?. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: subfsr 2, 23h before instruction fsr2 = 03ffh after instruction fsr2 = 03dch subulnk subtract literal from fsr2 and return syntax: subulnk k operands: 0 k 63 operation: fsr2 ? k fsr2 (tos) pc status affected: none encoding: 1110 1001 11kk kkkk description: the 6-bit literal ?k? is subtracted from the contents of the fsr2. a return is then executed by loading the pc with the tos. the instruction takes two cycles to execute; a nop is performed during the second cycle. this may be thought of as a special case of the subfsr instruction, where f = 3 (binary ? 11 ?); it operates only on fsr2. words: 1 cycles: 2 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination no operation no operation no operation no operation example: subulnk 23h before instruction fsr2 = 03ffh pc = 0100h after instruction fsr2 = 03dch pc = (tos)
pic18f1230/1330 ds39758b-page 254 advance information ? 2006 microchip technology inc. 21.2.3 byte-oriented and bit-oriented instructions in indexed literal offset mode in addition to eight new commands in the extended set, enabling the extended instruction set also enables indexed literal offset addressing mode ( section 5.5.1 ?indexed addressing with literal offset? ). this has a significant impact on the way that many commands of the standard pic18 instruction set are interpreted. when the extended set is disabled, addresses embed- ded in opcodes are treated as literal memory locations: either as a location in the access bank (?a? = 0 ) or in a gpr bank designated by the bsr (?a? = 1 ). when the extended instruction set is enabled and ?a? = 0 , however, a file register argument of 5fh or less is interpreted as an offset from the pointer value in fsr2 and not as a literal address. for practical purposes, this means that all instructions that use the access ram bit as an argument ? that is, all byte-oriented and bit- oriented instructions, or almost half of the core pic18 instructions ? may behave differently when the extended instruction set is enabled. when the content of fsr2 is 00h, the boundaries of the access ram are essentially remapped to their original values. this may be useful in creating backward compatible code. if this technique is used, it may be necessary to save the value of fsr2 and restore it when moving back and forth between c and assembly routines in order to preserve the stack pointer. users must also keep in mind the syntax requirements of the extended instruction set (see section 21.2.3.1 ?extended instruction syntax with standard pic18 commands? ). although the indexed literal offset addressing mode can be very useful for dynamic stack and pointer manipulation, it can also be very annoying if a simple arithmetic operation is carried out on the wrong register. users who are accustomed to the pic18 programming must keep in mind that, when the extended instruction set is enabled, register addresses of 5fh or less are used for indexed literal offset addressing mode. representative examples of typical byte-oriented and bit-oriented instructions in the indexed literal offset addressing mode are provided on the following page to show how execution is affected. the operand conditions shown in the examples are applicable to all instructions of these types. 21.2.3.1 extended instruction syntax with standard pic18 commands when the extended instruction set is enabled, the file register argument, ?f?, in the standard byte-oriented and bit-oriented commands is replaced with the literal offset value, ?k?. as already noted, this occurs only when ?f? is less than or equal to 5fh. when an offset value is used, it must be indicated by square brackets (?[ ]?). as with the extended instructions, the use of brackets indicates to the compiler that the value is to be interpreted as an index or an offset. omitting the brackets, or using a value greater than 5fh within brackets, will generate an error in the mpasm assembler. if the index argument is properly bracketed for indexed literal offset addressing mode, the access ram argument is never specified; it will automatically be assumed to be ? 0 ?. this is in contrast to standard operation (extended instruction set disabled) when ?a? is set on the basis of the target address. declaring the access ram bit in this mode will also generate an error in the mpasm assembler. the destination argument, ?d?, functions as before. in the latest versions of the mpasm assembler, language support for the extended instruction set must be explicitly invoked. this is done with either the command line option, /y , or the pe directive in the source listing. 21.2.4 considerations when enabling the extended instruction set it is important to note that the extensions to the instruc- tion set may not be beneficial to all users. in particular, users who are not writing code that uses a software stack may not benefit from using the extensions to the instruction set. additionally, the indexed literal offset addressing mode may create issues with legacy applications written to the pic18 assembler. this is because instructions in the legacy code may attempt to address registers in the access bank below 5fh. since these addresses are interpreted as literal offsets to fsr2 when the instruction set extension is enabled, the application may read or write to the wrong data addresses. when porting an application to the pic18f1230/1330, it is very important to consider the type of code. a large, re-entrant application that is written in ?c? and would benefit from efficient compilation will do well when using the instruction set extensions. legacy applications that heavily use the access bank will most likely not benefit from using the extended instruction set. note: enabling the pic18 instruction set extension may cause legacy applications to behave erratically or fail entirely.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 255 addwf add w to indexed (indexed literal offset mode) syntax: addwf [k] {,d} operands: 0 k 95 d [0,1] operation: (w) + ((fsr2) + k) dest status affected: n, ov, c, dc, z encoding: 0010 01d0 kkkk kkkk description: the contents of w are added to the contents of the register indicated by fsr2, offset by the value ?k?. if ?d? is ? 0 ?, the result is stored in w. if ?d? is ? 1 ?, the result is stored back in register ?f? (default). words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write to destination example: addwf [ofst] , 0 before instruction w = 17h ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 20h after instruction w = 37h contents of 0a2ch = 20h bsf bit set indexed (indexed literal offset mode) syntax: bsf [k], b operands: 0 f 95 0 b 7 operation: 1 ((fsr2) + k) status affected: none encoding: 1000 bbb0 kkkk kkkk description: bit ?b? of the register indicated by fsr2, offset by the value ?k?, is set. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read register ?f? process data write to destination example: bsf [flag_ofst], 7 before instruction flag_ofst = 0ah fsr2 = 0a00h contents of 0a0ah = 55h after instruction contents of 0a0ah = d5h setf set indexed (indexed literal offset mode) syntax: setf [k] operands: 0 k 95 operation: ffh ((fsr2) + k) status affected: none encoding: 0110 1000 kkkk kkkk description: the contents of the register indicated by fsr2, offset by ?k?, are set to ffh. words: 1 cycles: 1 q cycle activity: q1 q2 q3 q4 decode read ?k? process data write register example: setf [ofst] before instruction ofst = 2ch fsr2 = 0a00h contents of 0a2ch = 00h after instruction contents of 0a2ch = ffh
pic18f1230/1330 ds39758b-page 256 advance information ? 2006 microchip technology inc. 21.2.5 special considerations with microchip mplab ? ide tools the latest versions of microchip?s software tools have been designed to fully support the extended instruction set of the pic18f1230/1330 family of devices. this includes the mplab c18 c compiler, mpasm assem- bly language and mplab integrated development environment (ide). when selecting a target device for software development, mplab ide will automatically set default configuration bits for that device. the default setting for the xinst configuration bit is ? 0 ?, disabling the extended instruction set and indexed literal offset addressing mode. for proper execution of applications developed to take advantage of the extended instruction set, xinst must be set during programming. to develop software for the extended instruction set, the user must enable support for the instructions and the indexed addressing mode in their language tool(s). depending on the environment being used, this may be done in several ways: ? a menu option, or dialog box within the environment, that allows the user to configure the language tool and its settings for the project ? a command line option ? a directive in the source code these options vary between different compilers, assemblers and development environments. users are encouraged to review the documentation accompany- ing their development systems for the appropriate information.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 257 22.0 electrical characteristics absolute maximum ratings (?) ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on any pin with respect to v ss (except v dd and mclr ) ................................................... -0.3v to (v dd + 0.3v) voltage on v dd with respect to v ss ......................................................................................................... -0.3v to +7.5v voltage on mclr with respect to v ss (note 2) ......................................................................................... 0v to +13.25v total power dissipation (note 1) ............................................................................................................................... 1.0w maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin ........................................................................................................................... ...250 ma input clamp current, i ik (v i < 0 or v i > v dd ) ...................................................................................................................... 20 ma output clamp current, i ok (v o < 0 or v o > v dd ) .............................................................................................................. 20 ma maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by all ports ...................................................................................................................... .200 ma maximum current sourced by all ports ........................................................................................... .......................200 ma note 1: power dissipation is calculated as follows: pdis = v dd x {i dd ? i oh } + {(v dd ? v oh ) x i oh } + (v ol x i ol ) 2: voltage spikes below v ss at the mclr /v pp /ra5/flta pin, inducing currents greater than 80 ma, may cause latch-up. thus, a series resistor of 50-100 should be used when applying a ?low? level to the mclr / v pp /ra5/flta pin, rather than pulling this pin directly to v ss . ? notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic18f1230/1330 ds39758b-page 258 advance information ? 2006 microchip technology inc. figure 22-1: pic18f1230/1330 voltage-frequency graph (industrial) figure 22-2: pic18f1230/1330 voltage-frequency graph (extended) frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 40 mhz 5.0v 3.5v 3.0v 2.5v pic18f1230/1330 4.2v frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 25 mhz 5.0v 3.5v 3.0v 2.5v pic18f1230/1330 4.2v
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 259 figure 22-3: pic18lf1230/1330 voltage-frequency graph (industrial) frequency voltage 6.0v 5.5v 4.5v 4.0v 2.0v 40 mhz 5.0v 3.5v 3.0v 2.5v pic18lf1230/1330 f max = (16.36 mhz/v) (v ddappmin ? 2.0v) + 4 mhz note: v ddappmin is the minimum voltage of the picmicro ? device in the application. 4 mhz 4.2v
pic18f1230/1330 ds39758b-page 260 advance information ? 2006 microchip technology inc. 22.1 dc characteristics: supply voltage pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. symbol characteristic min typ max units conditions d001 v dd supply voltage pic18lf1230/1330 2.0 ? 5.5 v hs, xt, rc and lp oscillator modes pic18f1230/1330 4.2 ? 5.5 v d002 v dr ram data retention voltage (1) 1.5 ? ? v d003 v por v dd start voltage to ensure internal power-on reset signal ? ? 0.7 v see section on power-on reset for details d004 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms see section on power-on reset for details v bor brown-out reset voltage d005 pic18lf1230/1330 borv1:borv0 = 11 2.00 2.05 2.16 v borv1:borv0 = 10 2.65 2.79 2.93 v d005 all devices borv1:borv0 = 01 4.11 4.33 4.55 v borv1:borv0 = 00 4.36 4.59 4.82 v legend: shading of rows is to assist in readability of the table. note 1: this is the limit to which v dd can be lowered in sleep mode, or during a device reset, without losing ram data.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 261 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions power-down current (i pd ) (1) pic18lf1230/1330 100 tbd na -40c v dd = 2.0v ( sleep mode) 0.1 tbd a+25c 0.2 tbd a+85c pic18lf1230/1330 0.1 tbd a-40c v dd = 3.0v ( sleep mode) 0.1 tbd a+25c 0.3 tbd a+85c all devices 0.1 tbd a-40c v dd = 5.0v ( sleep mode) 0.1 tbd a+25c 0.4 tbd a+85c extended devices only 10 tbd a +125c legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ds39758b-page 262 advance information ? 2006 microchip technology inc. supply current (i dd ) (2) pic18lf1230/1330 15 tbd a -40c v dd = 2.0v f osc = 31 khz ( rc_run mode, intrc source) 15 tbd a+25c 15 tbd a+85c pic18lf1230/1330 40 tbd a -40c v dd = 3.0v 35 tbd a+25c 30 tbd a+85c all devices 105 tbd a -40c v dd = 5.0v 90 tbd a+25c 80 tbd a+85c extended devices only 80 tbd a +125c pic18lf1230/1330 0.32 tbd ma -40c v dd = 2.0v f osc = 1 mhz ( rc_run mode, intosc source) 0.33 tbd ma +25c 0.33 tbd ma +85c pic18lf1230/1330 0.6 tbd ma -40c v dd = 3.0v 0.55 tbd ma +25c 0.6 tbd ma +85c all devices 1.1 tbd ma -40c v dd = 5.0v 1.1 tbd ma +25c 1.0 tbd ma +85c extended devices only 1 tbd ma +125c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 263 supply current (i dd ) (2) pic18lf1230/1330 0.8 tbd a -40c v dd = 2.0v f osc = 4 mhz ( rc_run mode, intosc source) 0.8 tbd a+25c 0.8 tbd a+85c pic18lf1230/1330 1.3 tbd ma -40c v dd = 3.0v 1.3 tbd ma +25c 1.3 tbd ma +85c all devices 2.5 tbd ma -40c v dd = 5.0v 2.5 tbd ma +25c 2.5 tbd ma +85c extended devices only 2.5 tbd ma +125c pic18lf1230/1330 2.9 tbd a -40c v dd = 2.0v f osc = 31 khz ( rc_idle mode, intrc source) 3.1 tbd a+25c 3.6 tbd a+85c pic18lf1230/1330 4.5 tbd a -40c v dd = 3.0v 4.8 tbd a+25c 5.8 tbd a+85c all devices 9.2 tbd a -40c v dd = 5.0v 9.8 tbd a+25c 11.4 tbd a+85c extended devices only 21 tbd a +125c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ds39758b-page 264 advance information ? 2006 microchip technology inc. supply current (i dd ) (2) pic18lf1230/1330 165 tbd a -40c v dd = 2.0v f osc = 1 mhz ( rc_idle mode, intosc source) 175 tbd a+25c 190 tbd a+85c pic18lf1230/1330 250 tbd a -40c v dd = 3.0v 270 tbd a+25c 290 tbd a+85c all devices 500 tbd ma -40c v dd = 5.0v 520 tbd ma +25c 550 tbd ma +85c extended devices only 0.6 tbd ma +125c pic18lf1230/1330 340 tbd a -40c v dd = 2.0v f osc = 4 mhz ( rc_idle mode, intosc source) 350 tbd a+25c 360 tbd a+85c pic18lf1230/1330 520 tbd a -40c v dd = 3.0v 540 tbd a+25c 580 tbd a+85c all devices 1.0 tbd ma -40c v dd = 5.0v 1.1 tbd ma +25c 1.1 tbd ma +85c extended devices only 1.1 tbd ma +125c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 265 supply current (i dd ) (2) pic18lf1230/1330 250 tbd a -40c v dd = 2.0v f osc = 1 mhz ( pri_run , ec oscillator) 260 tbd a+25c 250 tbd a+85c pic18lf1230/1330 550 tbd a -40c v dd = 3.0v 480 tbd a+25c 460 tbd a+85c all devices 1.2 tbd ma -40c v dd = 5.0v 1.1 tbd ma +25c 1.0 tbd ma +85c extended devices only 1.0 tbd ma +125c pic18lf1230/1330 0.72 tbd ma -40c v dd = 2.0v f osc = 4 mhz ( pri_run , ec oscillator) 0.74 tbd ma +25c 0.74 tbd ma +85c pic18lf1230/1330 1.3 tbd ma -40c v dd = 3.0v 1.3 tbd ma +25c 1.3 tbd ma +85c all devices 2.7 tbd ma -40c v dd = 5.0v 2.6 tbd ma +25c 2.5 tbd ma +85c extended devices only 2.6 tbd ma +125c extended devices only 8.4 tbd ma +125c v dd = 4.2v f osc = 25 mhz ( pri_run , ec oscillator) 11 tbd ma +125c v dd = 5.0v all devices 15 tbd ma -40c v dd = 4.2v f osc = 40 mhz ( pri_run , ec oscillator) 16 tbd ma +25c 16 tbd ma +85c all devices 21 tbd ma -40c v dd = 5.0v 21 tbd ma +25c 21 tbd ma +85c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ds39758b-page 266 advance information ? 2006 microchip technology inc. supply current (i dd ) (2) all devices 7.5 tbd ma -40c v dd = 4.2v f osc = 4 mhz, 16 mhz internal ( pri_run hs+pll ) 7.4 tbd ma +25c 7.3 tbd ma +85c extended devices only 8.0 tbd ma +125c all devices 10 tbd ma -40c v dd = 5.0v f osc = 4 mhz, 16 mhz internal ( pri_run hs+pll ) 10 tbd ma +25c 9.7 tbd ma +85c extended devices only 10 tbd ma +125c all devices 17 tbd ma -40c v dd = 4.2v f osc = 10 mhz, 40 mhz internal ( pri_run hs+pll ) 17 tbd ma +25c 17 tbd ma +85c all devices 23 tbd ma -40c v dd = 5.0v f osc = 10 mhz, 40 mhz internal ( pri_run hs+pll ) 23 tbd ma +25c 23 tbd ma +85c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 267 supply current (i dd ) (2) pic18lf1230/1330 65 tbd a -40c v dd = 2.0v f osc = 1 mhz ( pri_idle mode, ec oscillator) 65 tbd a+25c 70 tbd a+85c pic18lf1230/1330 120 tbd a -40c v dd = 3.0v 120 tbd a+25c 130 tbd a+85c all devices 300 tbd a -40c v dd = 5.0v 240 tbd a+25c 300 tbd a+85c extended devices only 320 tbd a +125c pic18lf1230/1330 260 tbd a -40c v dd = 2.0v f osc = 4 mhz ( pri_idle mode, ec oscillator) 255 tbd a+25c 270 tbd a+85c pic18lf1230/1330 420 tbd a -40c v dd = 3.0v 430 tbd a+25c 450 tbd a+85c all devices 0.9 tbd ma -40c v dd = 5.0v 0.9 tbd ma +25c 0.9 tbd ma +85c extended devices only 1 tbd ma +125c extended devices only 2.8 tbd ma +125c v dd = 4.2v f osc = 25 mhz ( pri_idle mode, ec oscillator) 4.3 tbd ma +125c v dd = 5.0v all devices 6.0 tbd ma -40c v dd = 4.2v f osc = 40 mhz ( pri_idle mode, ec oscillator) 6.2 tbd ma +25c 6.6 tbd ma +85c all devices 8.1 tbd ma -40c v dd = 5.0v 9.1 tbd ma +25c 8.3 tbd ma +85c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ds39758b-page 268 advance information ? 2006 microchip technology inc. supply current (i dd ) (2) pic18lf1230/1330 14 tbd a -40c v dd = 2.0v f osc = 32 khz (4) ( sec_run mode, timer1 as clock) 15 tbd a+25c 16 tbd a+85c pic18lf1230/1330 40 tbd a -40c v dd = 3.0v 35 tbd a+25c 31 tbd a+85c all devices 99 tbd a -40c v dd = 5.0v 81 tbd a+25c 75 tbd a+85c pic18lf1230/1330 2.5 tbd a -40c v dd = 2.0v f osc = 32 khz (4) ( sec_idle mode, timer1 as clock) 3.7 tbd a+25c 4.5 tbd a+85c pic18lf1230/1330 5.0 tbd a -40c v dd = 3.0v 5.4 tbd a+25c 6.3 tbd a+85c all devices 8.5 tbd a -40c v dd = 5.0v 9.0 tbd a+25c 10.5 tbd a+85c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 269 module differential currents ( i wdt , i bor , i lvd , i oscb , i ad ) d022 ( i wdt ) watchdog timer 1.3 tbd a -40c v dd = 2.0v 1.4 tbd a+25c 2.0 tbd a+85c 1.9 tbd a -40c v dd = 3.0v 2.0 tbd a+25c 2.8 tbd a+85c 4.0 tbd a -40c v dd = 5.0v 5.5 tbd a+25c 5.6 tbd a+85c 13 tbd a +125c d022a ( i bor ) brown-out reset (4) 35 tbd a -40c to +85c v dd = 3.0v 40 tbd a -40c to +85c v dd = 5.0v 55 tbd a -40c to +125c 0tbd a -40c to +85c sleep mode, boren1:boren0 = 10 0tbd a -40c to +125c d022b ( i lvd ) low-voltage detect (4) 22 tbd a -40c to +85c v dd = 2.0v 25 tbd a -40c to +85c v dd = 3.0v 29 tbd a -40c to +85c v dd = 5.0v 30 tbd a -40c to +125c d025 ( i oscb ) timer1 oscillator 2.1 tbd a -40c v dd = 2.0v 32 khz on timer1 (3) 1.8 tbd a+25c 2.1 tbd a+85c 2.2 tbd a -40c v dd = 3.0v 32 khz on timer1 (3) 2.6 tbd a+25c 2.9 tbd a+85c 3.0 tbd a -40c v dd = 5.0v 32 khz on timer1 (3) 3.2 tbd a+25c 3.4 tbd a+85c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ds39758b-page 270 advance information ? 2006 microchip technology inc. module differential currents ( i wdt , i bor , i lvd , i oscb , i ad ) d026 ( i ad ) a/d converter 1.0 tbd a -40c to +85c v dd = 2.0v a/d on, not converting 1.0 tbd a -40c to +85c v dd = 3.0v 1.0 tbd a -40c to +85c v dd = 5.0v 2.0 tbd a -40c to +125c 22.2 dc characteristics: power-down and supply current pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial, extended) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial -40c t a +125c for extended param no. device typ max units conditions legend: tbd = to be determined. shading of rows is to assist in readability of the table. note 1: the power-down current in sleep mode does not depend on the oscillator type. power-down current is measured with the part in sleep mode, with all i/o pins in high-impedance state and tied to v dd or v ss and all features that add delta current disabled (such as wdt, timer1 oscillator, bor, etc.). 2: the supply current is mainly a function of operating voltage, frequency and mode. other factors, such as i/o pin loading and switching rate, oscillator type and circuit, internal code execution pattern and temperature, also have an impact on the current consumption. the test conditions for all i dd measurements in active operation mode are: osc1 = external square wave, from rail-to-rail; all i/o pins tri-stated, pulled to v dd or v ss ; mclr = v dd ; wdt enabled/disabled as specified. 3: low-power timer1 oscillator selected. 4: bor and lvd enable internal band gap reference. with both modules enabled, current consumption will be less than the sum of both specifications.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 271 22.3 dc characteristics: pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min max units conditions v il input low voltage i/o ports: d030 with ttl buffer v ss 0.15 v dd vv dd < 4.5v d030a ? 0.8 v 4.5v v dd 5.5v d031 with schmitt trigger buffer v ss 0.2 v dd v d032 mclr v ss 0.2 v dd v d033 osc1 v ss 0.3 v dd v hs, hspll modes d033a d033b d034 osc1 osc1 t1cki v ss v ss v ss 0.2 v dd 0.3 0.3 v v v rc, ec modes (1) xt, lp modes v ih input high voltage i/o ports: d040 with ttl buffer 0.25 v dd + 0.8v v dd vv dd < 4.5v d040a 2.0 v dd v4.5v v dd 5.5v d041 with schmitt trigger buffer 0.8 v dd v dd v d042 mclr 0.8 v dd v dd v d043 osc1 0.7 v dd v dd v hs, hspll modes d043a d043b d043c d044 osc1 osc1 osc1 t1cki 0.8 v dd 0.9 v dd 1.6 1.6 v dd v dd v dd v dd v v v v ec mode rc mode (1) xt, lp modes i il input leakage current (2,3) d060 i/o ports ? 1 av ss v pin v dd , pin at high-impedance d061 mclr ? 5 avss v pin v dd d063 osc1 ? 5 avss v pin v dd i pu weak pull-up current d070 i purb portb weak pull-up current 50 400 av dd = 5v, v pin = v ss note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the picmicro ? device be driven with an external clock while in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: parameter is characterized but not tested.
pic18f1230/1330 ds39758b-page 272 advance information ? 2006 microchip technology inc. v ol output low voltage d080 i/o ports ? 0.6 v i ol = 8.5 ma, v dd = 4.5v, -40 c to +85 c d083 osc2/clko (rc, rcio, ec, ecio modes) ?0.6vi ol = 1.6 ma, v dd = 4.5v, -40 c to +85 c v oh output high voltage (3) d090 i/o ports v dd ? 0.7 ? v i oh = -3.0 ma, v dd = 4.5v, -40 c to +85 c d092 osc2/clko (rc, rcio, ec, ecio modes) v dd ? 0.7 ? v i oh = -1.3 ma, v dd = 4.5v, -40 c to +85 c capacitive loading specs on output pins d100 (4) cosc2 osc2 pin ? 15 pf in xt, hs and lp modes when external clock is used to drive osc1 d101 c io all i/o pins and osc2 (in rc mode) ? 50 pf to meet the ac timing specifications 22.3 dc characteristics: pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) (continued) dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min max units conditions note 1: in rc oscillator configuration, the osc1/clki pin is a schmitt trigger input. it is not recommended that the picmicro ? device be driven with an external clock while in rc mode. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: parameter is characterized but not tested.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 273 table 22-1: memory programming requirements dc characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ? max units conditions data eeprom memory d120 e d byte endurance 100k 1m ? e/w -40 c to +85 c d121 v drw v dd for read/write v min ? 5.5 v using eecon to read/write v min = minimum operating voltage d122 t dew erase/write cycle time ? 4 ? ms d123 t retd characteristic retention 40 ? ? year provided no other specifications are violated d124 t ref number of total erase/write cycles before refresh (1) 1m 10m ? e/w -40c to +85c d125 i ddp supply current during programming ?10?ma program flash memory d130 e p cell endurance 10k 100k ? e/w -40 c to +85 c d131 v pr v dd for read v min ?5.5vv min = minimum operating voltage d132b v pew v dd for self-timed write v min ?5.5vv min = minimum operating voltage d133a t iw self-timed write cycle time ? 2 ? ms d134 t retd characteristic retention 40 100 ? year provided no other specifications are violated d135 i ddp supply current during programming ?10?ma ? data in ?typ? column is at 5.0v, 25c unless otherwise stated. these parameters are for design guidance only and are not tested. note 1: refer to section 7.8 ?using the data eeprom? for a more detailed discussion on data eeprom endurance.
pic18f1230/1330 ds39758b-page 274 advance information ? 2006 microchip technology inc. table 22-2: comparator specifications table 22-3: voltage reference specifications operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +85c (unless otherwise stated). param no. sym characteristics min typ max units comments d300 v ioff input offset voltage ? 5.0 10 mv d301 v icm input common mode voltage 0 ? v dd ? 1.5 v d302 cmrr common mode rejection ratio 55 ? ? db 300 t resp response time (1) ? 150 400 ns pic18 f xxxx 300a ? 150 600 ns pic18 lf xxxx, v dd = 2.0v 301 t mc 2 ov comparator mode change to output valid ?? 10 s note 1: response time measured with one comparator input at (v dd ? 1.5)/2, while the other input transitions from v ss to v dd . operating conditions: 3.0v < v dd < 5.5v, -40c < t a < +85c (unless otherwise stated). param no. sym characteristics min typ max units comments d310 v res resolution v dd /24 ? v dd /32 lsb d311 vr aa absolute accuracy ? ? 1/2 lsb d312 vr ur unit resistor value (r) ? 2k ? 310 t set settling time (1) ? ? 10 s note 1: settling time measured while cvrr = 1 and cvr3:cvr0 transitions from ? 0000 ? to ? 1111 ?.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 275 figure 22-4: low-voltage detect characteristics table 22-4: low-voltage detect characteristics v lvd lvdif v dd (lvdif set by hardware) (lvdif can be cleared in software) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ max units conditions d420 lvd voltage on v dd transition high-to-low lvdl<3:0> = 0000 2.06 2.17 2.28 v lvdl<3:0> = 0001 2.12 2.23 2.34 v lvdl<3:0> = 0010 2.24 2.36 2.48 v lvdl<3:0> = 0011 2.32 2.44 2.56 v lvdl<3:0> = 0100 2.47 2.60 2.73 v lvdl<3:0> = 0101 2.65 2.79 2.93 v lvdl<3:0> = 0110 2.74 2.89 3.04 v lvdl<3:0> = 0111 2.96 3.12 3.28 v lvdl<3:0> = 1000 3.22 3.39 3.56 v lvdl<3:0> = 1001 3.37 3.55 3.73 v lvdl<3:0> = 1010 3.52 3.71 3.90 v lvdl<3:0> = 1011 3.70 3.90 4.10 v lvdl<3:0> = 1100 3.90 4.11 4.32 v lvdl<3:0> = 1101 4.11 4.33 4.55 v lvdl<3:0> = 1110 4.36 4.59 4.82 v
pic18f1230/1330 ds39758b-page 276 advance information ? 2006 microchip technology inc. 22.4 ac (timing) characteristics 22.4.1 timing parameter symbology the timing parameter symbols have been created using one of the following formats: 1. tpps2pps 3. t cc : st (i 2 c specifications only) 2. tpps 4. ts (i 2 c specifications only) t f frequency t time lowercase letters (pp) and their meanings: pp cc ccp1 osc osc1 ck clko rd rd cs cs rw rd or wr di sdi sc sck do sdo ss ss dt data in t0 t0cki io i/o port t1 t13cki mc mclr wr wr uppercase letters and their meanings: s f fall p period hhigh rrise i invalid (high-impedance) v valid l low z high-impedance i 2 c only aa output access high high buf bus free low low t cc : st (i 2 c specifications only) cc hd hold su setup st dat data input hold sto stop condition sta start condition
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 277 22.4.2 timing conditions the temperature and voltages specified in table 22-5 apply to all timing specifications unless otherwise noted. figure 22-5 specifies the load conditions for the timing specifications. table 22-5: temperature and voltage specifications ? ac figure 22-5: load conditions for devi ce timing specifications note: because of space limitations, the generic terms ?pic18fxxxx? and ?pic18lfxxxx? are used throughout this section to refer to the pic18f1230/1330 and pic18lf1230/ 1330 families of devices specifically and only those devices. ac characteristics standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial operating voltage v dd range as described in dc spec section 22.1 and section 22.3 . lf parts operate for industrial temperatures only. v dd /2 c l r l pin pin v ss v ss c l r l =464 c l = 50 pf for all pins except osc2/clko and including d and e outputs as ports load condition 1 load condition 2
pic18f1230/1330 ds39758b-page 278 advance information ? 2006 microchip technology inc. 22.4.3 timing diagrams and specifications figure 22-6: external clock timing (all modes except pll) table 22-6: external clock timing requirements param. no. symbol characteristic min max units conditions 1a f osc external clki frequency (1) dc 1 mhz xt, rc oscillator modes dc 20 mhz hs oscillator mode dc 31.25 khz lp oscillator mode oscillator frequency (1) dc 4 mhz rc oscillator mode 0.1 4 mhz xt oscillator mode 4 20 mhz hs oscillator mode 5 200 khz lp oscillator mode 1t osc external clki period (1) 1000 ? ns xt, rc oscillator modes 50 ? ns hs oscillator mode 32 ? s lp oscillator mode oscillator period (1) 250 ? ns rc oscillator mode 250 1 s xt oscillator mode 100 250 ns hs oscillator mode 50 250 ns hs oscillator mode 5? s lp oscillator mode 2t cy instruction cycle time (1) 100 ? ns t cy = 4/f osc , industrial 160 ? ns t cy = 4/f osc , extended 3t os l, t os h external clock in (osc1) high or low time 30 ? ns xt oscillator mode 2.5 ? s lp oscillator mode 10 ? ns hs oscillator mode 4t os r, t os f external clock in (osc1) rise or fall time ? 20 ns xt oscillator mode ? 50 ns lp oscillator mode ? 7.5 ns hs oscillator mode note 1: instruction cycle period (t cy ) equals four times the input oscillator time base period for all configurations except pll. all specified values are based on characteri zation data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osc1/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. osc1 clko q4 q1 q2 q3 q4 q1 1 2 33 4 4
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 279 table 22-7: pll clock timing specifications (v dd = 4.2v to 5.5v) table 22-8: ac characteristics: internal rc accuracy pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) param no. sym characteristic min typ? max units conditions f10 f osc oscillator frequency range 4 ? 10 mhz hs mode only f11 f sys on-chip vco system frequency 16 ? 40 mhz hs mode only f12 t rc pll start-up time (lock time) ? ? 2 ms f13 clk clko stability (jitter) -2 ? +2 % ? data in ?typ? column is at 5v, 25 c unless otherwise stated. these parameters are for design guidance only and are not tested. pic18lf1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial pic18f1230/1330 (industrial) standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. device min typ max units conditions intosc accuracy @ freq = 8 mhz, 4 mhz, 2 mhz, 1 mhz, 500 khz, 250 khz, 125 khz, 31 khz (1) pic18lf1230/1330 -2 +/-1 2 % +25c v dd = 2.7-3.3v -5 ? 5 % -10c to +85c v dd = 2.7-3.3v -10 +/-1 10 % -40c to +85c v dd = 2.7-3.3v pic18f1230/1330 -2 +/-1 2 % +25c v dd = 4.5-5.5v -5 ? 5 % -10c to +85c v dd = 4.5-5.5v -10 +/-1 10 % -40c to +85c v dd = 4.5-5.5v intrc accuracy @ freq = 31 khz (2,3) pic18lf1230/1330 26.562 ? 35.938 khz -40c to +85c v dd = 2.7-3.3v pic18f1230/1330 26.562 ? 35.938 khz -40c to +85c v dd = 4.5-5.5v legend: shading of rows is to assist in readability of the table. note 1: frequency calibrated at 25c. osctune register can be used to compensate for temperature drift. 2: intrc frequency after calibration. 3: change of intrc frequency as v dd changes.
pic18f1230/1330 ds39758b-page 280 advance information ? 2006 microchip technology inc. figure 22-7: clko and i/o timing table 22-9: clko and i/o timing requirements param no. symbol characteristic min typ max units conditions 10 tosh2ckl osc1 to clko ? 75 200 ns (note 1) 11 tosh2ckh osc1 to clko ? 75 200 ns (note 1) 12 tckr clko rise time ? 35 100 ns (note 1) 13 tckf clko fall time ? 35 100 ns (note 1) 14 tckl2iov clko to port out valid ? ? 0.5 t cy + 20 ns (note 1) 15 tiov2ckh port in valid before clko 0.25 t cy + 25 ? ? ns (note 1) 16 tckh2ioi port in hold after clko 0??ns (note 1) 17 tosh2iov osc1 (q1 cycle) to port out valid ? 50 150 ns 18 tosh2ioi osc1 (q2 cycle) to port input invalid (i/o in hold time) pic18 f xxxx 100 ? ? ns 18a pic18 lf xxxx 200 ? ? ns v dd = 2.0v 19 tiov2osh port input valid to osc1 (i/o in setup time) 0 ? ? ns 20 tior port output rise time pic18 f xxxx ? 10 25 ns 20a pic18 lf xxxx ? ? 60 ns v dd = 2.0v 21 tiof port output fall time pic18 f xxxx ? 10 25 ns 21a pic18 lf xxxx ? ? 60 ns v dd = 2.0v 22? t inp intx pin high or low time t cy ??ns 23? t rbp rb7:rb4 change intx high or low time t cy ??ns ? these parameters are asynchronous events not related to any internal clock edges. note 1: measurements are taken in rc mode, where clko output is 4 x t osc . note: refer to figure 22-5 for load conditions. osc1 clko i/o pin (input) i/o pin (output) q4 q1 q2 q3 10 13 14 17 20, 21 19 18 15 11 12 16 old value new value
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 281 figure 22-8: reset, watchdog timer, oscillator start-up timer and power-up timer timing figure 22-9: brown-out reset timing table 22-10: reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements param. no. symbol characteristic min typ max units conditions 30 tmcl mclr pulse width (low) 2 ? ? s 31 t wdt watchdog timer time-out period (no postscaler) 3.4 4.0 4.6 ms 32 t ost oscillation start-up timer period 1024 t osc ? 1024 t osc ?t osc = osc1 period 33 t pwrt power-up timer period 55.6 65.5 75 ms 34 t ioz i/o high-impedance from mclr low or watchdog timer reset ?2? s 35 t bor brown-out reset pulse width 200 ? ? sv dd b vdd (see d005) 36 t irvst time for internal reference voltage to become stable ?2050 s 37 t lvd low-voltage detect pulse width 200 ? ? sv dd v lvd 38 t csd cpu start-up time ? 10 ? s 39 t iobst time for intosc to stabilize ? 1 ? s v dd mclr internal por pwrt time-out oscillator time-out internal reset watchdog timer reset 33 32 30 31 34 i/o pins 34 note: refer to figure 22-5 for load conditions. v dd bv dd 35 v irvst enable internal internal reference 36 reference voltage voltage stable
pic18f1230/1330 ds39758b-page 282 advance information ? 2006 microchip technology inc. figure 22-10: timer0 and timer1 external clock timings table 22-11: timer0 and timer1 external clock requirements param no. symbol characteristic min max units conditions 40 tt0h t0cki high pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 41 tt0l t0cki low pulse width no prescaler 0.5 t cy + 20 ? ns with prescaler 10 ? ns 42 tt0p t0cki period no prescaler t cy + 10 ? ns with prescaler greater of: 20 ns or (t cy + 40)/n ? ns n = prescale value (1, 2, 4,..., 256) 45 tt1h t1cki high time synchronous, no prescaler 0.5 t cy + 20 ? ns synchronous, with prescaler pic18 f xxxx 10 ? ns pic18 lf xxxx 25 ? ns v dd = 2.0v asynchronous pic18 f xxxx 30 ? ns pic18 lf xxxx 50 ? ns v dd = 2.0v 46 tt1l t1cki low time synchronous, no prescaler 0.5 t cy + 5 ? ns synchronous, with prescaler pic18 f xxxx 10 ? ns pic18 lf xxxx 25 ? ns v dd = 2.0v asynchronous pic18 f xxxx 30 ? ns pic18 lf xxxx 50 ? ns v dd = 2.0v 47 tt1p t1cki input period synchronous greater of: 20 ns or (t cy + 40)/n ? ns n = prescale value (1, 2, 4, 8) asynchronous 60 ? ns ft1 t1cki oscillator input frequency range dc 50 khz 48 tcke2tmri delay from external t1cki clock edge to timer increment 2 t osc 7 t osc ? note: refer to figure 22-5 for load conditions. 46 47 45 48 41 42 40 t0cki t1oso/t1cki tmr0 or tmr1
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 283 figure 22-11: eusart synchronous transmissi on (master/slave) timing table 22-12: eusart synchronous transmission requirements figure 22-12: eusart synchronous receive (master/slave) timing table 22-13: eusart synchronous receive requirements param no. symbol characteristic min max units conditions 120 tckh2dtv sync xmit (master & slave) clock high to data out valid pic18 f xxxx ? 40 ns pic18 lf xxxx ? 100 ns v dd = 2.0v 121 tckrf clock out rise time and fall time (master mode) pic18 f xxxx ? 20 ns pic18 lf xxxx ? 50 ns v dd = 2.0v 122 tdtrf data out rise time and fall time pic18 f xxxx ? 20 ns pic18 lf xxxx ? 50 ns v dd = 2.0v param. no. symbol characteristic min max units conditions 125 tdtv2ckl sync rcv (master & slave) data hold before ck (dt hold time) 10 ? ns 126 tckl2dtl data hold after ck (dt hold time) 15 ? ns 121 121 120 122 ra2/tx/ck ra3/rx/dt pin pin note: refer to figure 22-5 for load conditions. 125 126 ra2/tx/ck ra3/rx/dt pin pin note: refer to figure 22-5 for load conditions.
pic18f1230/1330 ds39758b-page 284 advance information ? 2006 microchip technology inc. table 22-14: a/d converter characteristics: pic18f1230/1330 (industrial) pic18lf1230/1330 (industrial) param no. symbol characteristic min typ max units conditions a01 n r resolution ? ? 10 bit v ref 3.0v a03 e il integral linearity error ? ? < 1 lsb v ref 3.0v a04 e dl differential linearity error ? ? < 1 lsb v ref 3.0v a06 e off offset error ? ? < 1.5 lsb v ref 3.0v a07 e gn gain error ? ? < 1 lsb v ref 3.0v a10 ? monotonicity guaranteed (1) ?v ss v ain v ref a20 v ref reference voltage range (v ref + ? v ss ) 1.8 3 ? ? ? ? v v v dd < 3.0v v dd 3.0v a21 v ref + positive reference voltage v ss ?v ref +v a25 v ain analog input voltage v ss ?v ref +v a30 z ain recommended impedance of analog voltage source ?? 2.5k a50 i ref v ref + input current (2) ? ? ? ? 5 150 a a during v ain acquisition. during a/d conversion cycle. note 1: the a/d conversion result never decreases with an increase in the input voltage and has no missing codes. 2: v ref + current is from ra4/t0cki/an2/v ref + pin or v dd , whichever is selected as the v ref + source.
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 285 figure 22-13: a/d conversion timing table 22-15: a/d conversion requirements param no. symbol characteristic min max units conditions 130 t ad a/d clock period pic18 f xxxx 0.7 25.0 (1) st osc based, v ref 3.0v pic18 lf xxxx 1.4 25.0 (1) sv dd = 2.0v, t osc based, v ref full range pic18 f xxxx tbd 1 s a/d rc mode pic18 lf xxxx tbd 3 sv dd = 2.0v, a/d rc mode 131 t cnv conversion time (not including acquisition time) (2) 11 12 t ad 132 t acq acquisition time (3) 1.4 tbd ? ? s s -40 c to +85 c 0 c to +85 c 135 t swc switching time from convert sample ? (note 4) tbd t dis discharge time 0.2 ? s legend: tbd = to be determined note 1: the time of the a/d clock period is dependent on the device frequency and the t ad clock divider. 2: adres register may be read on the following t cy cycle. 3: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (v dd to v ss or v ss to v dd ). the source impedance (r s ) on the input channels is 50 . 4: on the following cycle of the device clock. 131 130 132 bsf adcon0, go q4 a/d clk (1) a/d data adres adif go sample old_data sampling stopped done new_data (note 2) 98 7 2 1 0 note 1: if the a/d clock source is selected as rc, a time of t cy is added before the a/d clock starts. this allows the sleep instruction to be executed. 2: this is a minimal rc delay (typically 100 ns), which also disconnects the holding capacitor from the analog input. . . . . . . t cy
pic18f1230/1330 ds39758b-page 286 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 287 23.0 dc and ac characteristics graphs and tables graphs and tables are not available at this time.
pic18f1230/1330 ds39758b-page 288 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 289 24.0 packaging information 24.1 package marking information 18-lead pdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic18f1330-i/p 0510017 18-lead soic xxxxxxxxxxxx xxxxxxxxxxxx xxxxxxxxxxxx yywwnnn example pic18f1230- e/so 0510017 20-lead ssop xxxxxxxxxxx xxxxxxxxxxx yywwnnn example pic18f1230- e/ss 0510017 28-lead qfn xxxxxxxx xxxxxxxx yywwnnn example 18f1330 -i/ml 0510017 legend: xx...x customer-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 3 e 3 e 3 e 3 e
pic18f1230/1330 ds39758b-page 290 advance information ? 2006 microchip technology inc. 24.2 package details the following sections give the technical details of the packages. 18-lead plastic dual in-line (p) ? 300 mil body (pdip) 15 10 5 15 10 5 mold draft angle bottom 15 10 5 15 10 5 mold draft angle top 10.92 9.40 7.87 .430 .370 .310 eb overall row spacing 0.56 0.46 0.36 .022 .018 .014 b lower lead width 1.78 1.46 1.14 .070 .058 .045 b1 upper lead width 0.38 0.29 0.20 .015 .012 .008 c lead thickness 3.43 3.30 3.18 .135 .130 .125 l tip to seating plane 22.99 22.80 22.61 .905 .898 .890 d overall length 6.60 6.35 6.10 .260 .250 .240 e1 molded package width 8.26 7.94 7.62 .325 .313 .300 e shoulder to shoulder width 0.38 .015 a1 base to seating plane 3.68 3.30 2.92 .145 .130 .115 a2 molded package thickness 4.32 3.94 3.56 .170 .155 .140 a top to seating plane 2.54 .100 p pitch 18 18 n number of pins max nom min max nom min dimension limits millimeters inches * units 1 2 d n e1 c eb e p a2 l b1 b a a1 * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed .010? (0.254mm) per si de. jedec equivalent: ms-001 drawing no. c04-007 significant characteristic
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 291 18-lead plastic small outline (so) ? wide, 300 mil body (soic) foot angle 048048 15 12 0 15 12 0 mold draft angle bottom 15 12 0 15 12 0 mold draft angle top 0.51 0.42 0.36 .020 .017 .014 b lead width 0.30 0.27 0.23 .012 .011 .009 c lead thickness 1.27 0.84 0.41 .050 .033 .016 l foot length 0.74 0.50 0.25 .029 .020 .010 h chamfer distance 11.73 11.53 11.33 .462 .454 .446 d overall length 7.59 7.49 7.39 .299 .295 .291 e1 molded package width 10.67 10.34 10.01 .420 .407 .394 e overall width 0.30 0.20 0.10 .012 .008 .004 a1 standoff 2.39 2.31 2.24 .094 .091 .088 a2 molded package thickness 2.64 2.50 2.36 .104 .099 .093 a overall height 1.27 .050 p pitch 18 18 n number of pins max nom min max nom min dimension limits millimeters inches * units l c h 45 1 2 d p n b e1 e a2 a1 a * controlling parameter notes: dimensions d and e1 do not include mold flash or protrusions. mold flash or protrusions shall not exceed 010? (0.254mm) per sid e. jedec equivalent: ms-013 drawing no. c04-051 significant characteristic
pic18f1230/1330 ds39758b-page 292 advance information ? 2006 microchip technology inc. 20-lead plastic shrink small outline (ss) ? 209 mil body, 5.30 mm (ssop) * controlling param e t e r notes: dim e nsions d and e1 do no includ e mold flash or protrusions. mold flash or protrusions shall not e xc ee d 010" (0.254mm) p e r sid e . jedec equival e nt: mo-150 drawing no. c04-072 r e vis e d 8-27-04 units dim e nsion limits numb e r of pins pitch ov e rall h e ight mold e d packag e thickn e ss standoff ov e rall width mold e d packag e width ov e rall l e ngth foot l e ngth l e ad thickn e ss foot angl e l e ad width b .009 ? ? ? ? ? ? ? ? ? a p n .026 20 .065 20 max nom min millimeters * ? ? ? 0. 3 8 8 4 0 8 .010 0.09 0.25 0.95 0.75 0.55 0. 3 7 0. 3 0 0.22 l d .272 .28 3 .295 6.90 7.20 7.50 5.60 5. 3 0 5.00 .220 .209 .197 e1 e .291 . 3 07 . 3 2 3 7.40 0.05 .002 a1 a2 .065 .069 .07 3 .079 1.65 1.75 1.85 2.00 7.80 8.20 4 0 c .004 .015 0.22 inches a1 a2 d 2 e p b n c e1 1 l a min nom max
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 293 28-lead plastic quad flat no lead package (ml) 6x6 mm body (qfn) ? with 0.55 mm contact length (saw singulated) b d2 d pad outline alternate see detail a1 a detail top view optional index area 1 2 l bottom view n e metal pad alternate exposed indicators index e e2 ( note 1 ) ( note 2 ) k contact width significant characteristic notes: jedec equivalent: mo-220 .009 .011 .013 0.23 0.28 0.33 pitch number of pins overall width standoff overall length overall height max units dimension limits a1 d e n e a .000 inches .026 bsc min 28 nom max .002 0.00 6.00 millimeters * .039 min 28 0.65 bsc nom 0.05 1.00 0.90 .035 .001 0.02 contact length l .018 .022 .024 0.45 0.55 0.65 e2 d2 exposed pad width exposed pad length .153 .167 .169 3.89 4.24 4.29 .031 0.80 5.90 6.10 .240 .236 .232 .232 .236 6.00 .240 5.90 6.10 .153 .167 4.24 .169 3.89 4.29 contact thickness a3 .008 ref 0.20 ref ref: reference dimension, usually without tolerance, for information purposes only. bsc: basic dimension. theoretically exact value shown without tolerances. see asme y14.5m see asme y14.5m 1. pin 1 visual index feature may vary, but must be located within the hatched area. 2. exposed pad varies according to die attach paddle size. contact-to-exposed pad k.008 ? ? 0.20 ?? * controlling parameter revised 09-12-05 drawing no. c04-105
pic18f1230/1330 ds39758b-page 294 advance information ? 2006 microchip technology inc. notes:
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 295 appendix a: revision history revision a (november 2005) original data sheet for pic18f1230/1330 devices. revision b (february 2006) data bank information was updated and a note was added for calculating the pcpwm duty cycle. appendix b: device differences the differences between the devices listed in this data sheet are shown in table b-1. table b-1: device differences features pic18f1230 pic18f1330 program memory (bytes) 4096 8192 program memory (instructions) 2048 4096 packages 18-pin pdip 18-pin soic 20-pin ssop 28-pin qfn 18-pin pdip 18-pin soic 20-pin ssop 28-pin qfn
pic18f1230/1330 ds39758b-page 296 advance information ? 2006 microchip technology inc. appendix c: conversion considerations this appendix discusses the considerations for converting from previous versions of a device to the ones listed in this data sheet. typically, these changes are due to the differences in the process technology used. an example of this type of conversion is from a pic16c74a to a pic16c74b. not applicable appendix d: migration from baseline to enhanced devices this section discusses how to migrate from a baseline device (i.e., pic16c5x) to an enhanced mcu device (i.e., pic18fxxx). the following are the list of modifications over the pic16c5x microcontroller family: not currently available
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 297 appendix e: migration from mid-range to enhanced devices a detailed discussion of the differences between the mid-range mcu devices (i.e., pic16cxxx) and the enhanced devices (i.e., pic18fxxx) is provided in an716, ?migrating designs from pic16c74a/74b to pic18c442? . the changes discussed, while device specific, are generally applicable to all mid-range to enhanced device migrations. this application note is available as literature number ds00716. appendix f: migration from high-end to enhanced devices a detailed discussion of the migration pathway and differences between the high-end mcu devices (i.e., pic17cxxx) and the enhanced devices (i.e., pic18fxxx) is provided in an726, ?pic17cxxx to pic18cxxx migration? . this application note is available as literature number ds00726.
pic18f1230/1330 ds39758b-page 298 advance information ? 2006 microchip technology inc. notes:
? 2006 microchip technology inc. advance information ds39758b-page 299 pic18f1230/1330 index a a/d ................................................................................... 164 a/d converter interrupt, configuring ....................... 168 acquisition requirements ........................................ 169 adcon0 register .................................................... 164 adcon1 register .................................................... 164 adcon2 register .................................................... 164 adresh register ............................................ 164, 167 adresl register .................................................... 164 analog port pins, configuring .................................. 171 associated registers ............................................... 173 configuring the module ............................................ 168 conversion clock (t ad ) ........................................... 170 conversion requirements ....................................... 286 conversion status (go/done bit) .......................... 167 conversions ............................................................. 172 converter characteristics ........................................ 285 discharge ................................................................. 172 operation in power-managed modes ...................... 171 selecting and configuring acquisition time ............ 170 triggering conversions ............................................ 169 absolute maximum ratings ............................................. 258 ac (timing) characteristics ............................................. 277 conditions ................................................................ 278 load conditions for device timing specifications ....................................... 278 parameter symbology ............................................. 277 temperature and voltage specific ations ................. 278 ac characteristics internal rc accuracy ............................................... 280 access bank mapping with indexed literal offset addressing mode ............................................... 63 remapping with indexed literal offset addressing mode ............................................... 63 adcon0 register ............................................................ 164 go/done bit ........................................................... 167 adcon1 register ............................................................ 164 adcon2 register ............................................................ 164 addfsr .......................................................................... 251 addlw ............................................................................ 214 addulnk ........................................................................ 251 addwf ............................................................................ 214 addwfc ......................................................................... 215 adresh register ............................................................ 164 adresl register .................................................... 164, 167 analog-to-digital converter. see a/d. andlw ............................................................................ 215 andwf ............................................................................ 216 assembler mpasm assembler .................................................. 205 b bc .................................................................................... 216 bcf .................................................................................. 217 block diagrams a/d ........................................................................... 167 analog input model .................................................. 168 comparator analog input model .............................. 176 comparator voltage reference ............................... 179 dead-time control unit for one pwm output pair ..................................... 129 device clock .............................................................. 20 eusart receive .................................................... 154 eusart transmit ................................................... 152 external power-on reset circuit (slow v dd power-up) ........................................ 35 fail-safe clock monitor ........................................... 198 generic i/o port ......................................................... 81 interrupt logic ............................................................ 88 low-voltage detect ................................................. 181 on-chip reset circuit ................................................ 33 pic18f1230/1330 ..................................................... 10 pll (hs mode) .......................................................... 17 power control pwm ................................................ 112 pwm (one output pair, complementary mode) .................................... 113 pwm (one output pair, independent mode) ......................................... 113 pwm i/o pin ............................................................ 136 pwm time base ...................................................... 115 reads from flash program memory ......................... 69 single comparator ................................................... 175 table read operation ............................................... 65 table write operation ............................................... 66 table writes to flash program memory .................... 71 timer0 in 16-bit mode ............................................. 102 timer0 in 8-bit mode ............................................... 102 timer1 ..................................................................... 106 timer1 (16-bit read/write mode) ............................ 106 watchdog timer ...................................................... 195 bn .................................................................................... 217 bnc ................................................................................. 218 bnn ................................................................................. 218 bnov .............................................................................. 219 bnz ................................................................................. 219 bor. see brown-out reset. bov ................................................................................. 222 bra ................................................................................. 220 brown-out reset (bor) ..................................................... 36 detecting ................................................................... 36 disabling in sleep mode ............................................ 36 software enabled ...................................................... 36 bsf .................................................................................. 220 btfsc ............................................................................. 221 btfss ............................................................................. 221 btg ................................................................................. 222 bz .................................................................................... 223 c c compilers mplab c18 ............................................................. 205 mplab c30 ............................................................. 205 call ................................................................................ 223 callw ............................................................................ 252 clock sources .................................................................... 20 selecting the 31 khz source ..................................... 21 selection using osccon register .......................... 21 clrf ............................................................................... 224 clrwdt ......................................................................... 224
pic18f1230/1330 ds39758b-page 300 advance information ? 2006 microchip technology inc. code examples 16 x 16 signed multiply routine ................................ 80 16 x 16 unsigned multiply routine ............................ 80 8 x 8 signed multiply routine .................................... 79 8 x 8 unsigned multiply routine ................................ 79 computed goto using an offset value ................... 48 data eeprom read ................................................. 77 data eeprom refresh routine ................................ 78 data eeprom write ................................................. 77 erasing a flash program memory row ..................... 70 fast register stack .................................................... 48 how to clear ram (bank 0) using indirect addressing ............................................ 59 implementing a real-time clock using a timer1 interrupt service ............................... 109 initializing porta ...................................................... 81 initializing portb ...................................................... 84 reading a flash program memory word .................. 69 saving status, wreg and bsr registers in ram ....................................... 99 writing to flash program memory ....................... 72?73 code protection ....................................................... 184, 200 associated registers ............................................... 200 configuration register protection ............................ 203 data eeprom ......................................................... 203 program memory ..................................................... 201 comf ............................................................................... 225 comparator ...................................................................... 174 analog input connection considerations ................. 176 associated registers ............................................... 177 configuration ............................................................ 175 effects of a reset ..................................................... 176 interrupts .................................................................. 175 operation ................................................................. 175 operation during sleep ........................................... 176 outputs .................................................................... 175 reference ................................................................ 175 response time ........................................................ 175 comparator specifications ............................................... 275 comparator voltage reference ....................................... 178 accuracy and error .................................................. 179 associated registers ............................................... 179 configuring ............................................................... 178 effects of a reset ..................................................... 179 operation during sleep ........................................... 179 computed goto ............................................................... 48 configuration bits ............................................................. 184 context saving during interrupts ....................................... 99 conversion considerations .............................................. 297 cpfseq .......................................................................... 225 cpfsgt ........................................................................... 226 cpfslt ........................................................................... 226 crystal oscillator/ceramic resonator ................................ 15 customer change notification service ............................ 307 customer notification service .......................................... 307 customer support ............................................................ 307 d data addressing modes ..................................................... 59 comparing options with the extended instruction set enabled ...................... 62 direct .......................................................................... 59 indexed literal offset ................................................. 61 instructions affected .......................................... 61 indirect ....................................................................... 59 inherent and literal .................................................... 59 data eeprom memory ..................................................... 75 associated registers ................................................. 78 eeadr register ........................................................ 75 eecon1 and eecon2 registers ............................. 75 operation during code-protect ................................. 78 protection against spurious write ............................. 77 reading ..................................................................... 77 using ......................................................................... 78 write verify ................................................................ 77 writing ....................................................................... 77 data memory ..................................................................... 51 access bank .............................................................. 53 and the extended instruction set .............................. 61 bank select register (bsr) ...................................... 51 general purpose registers ....................................... 53 map for pic18f1230/1330 ........................................ 52 special function registers ........................................ 54 daw ................................................................................ 227 dc and ac characteristics graphs and tables .................................................. 288 dc characteristics ........................................................... 272 power-down and supply current ............................ 262 supply voltage ........................................................ 261 dcfsnz .......................................................................... 228 decf ............................................................................... 227 decfsz .......................................................................... 228 development support ...................................................... 204 device differences ........................................................... 296 device overview .................................................................. 7 details on individual family members .................................................. 8 features (table) ........................................................... 9 new core features ...................................................... 7 other special features ................................................ 8 device reset timers ......................................................... 37 oscillator start-up timer (ost) ................................. 37 pll lock time-out ..................................................... 37 power-up timer (pwrt) ........................................... 37 time-out sequence ................................................... 37 direct addressing .............................................................. 60 e effect on standard pic mcu instructions ....................... 255 effects of power-managed modes on various clock sources .............................................. 23 electrical characteristics ................................................. 258 enhanced universal synchronous asynchronous receiver transmitter (eusart). see eusart. equations a/d acquisition time ............................................... 169 a/d minimum charging time ................................... 169 calculating the minimum required acquisition time .............................................. 169 pwm frequency ...................................................... 123 pwm period for continuous up/down count mode ..................................... 123 pwm period for free-running mode ...................... 123 pwm resolution ...................................................... 123 errata ................................................................................... 5
? 2006 microchip technology inc. advance information ds39758b-page 301 pic18f1230/1330 eusart asynchronous mode ................................................ 151 12-bit break character sequence ................... 157 associated registers, receive ........................ 155 associated registers, transmit ....................... 153 auto-wake-up on sync break character ......... 155 receiver ........................................................... 154 receiving a break character ........................... 157 setting up 9-bit mode with address detect ........................................ 154 transmitter ....................................................... 151 baud rate generator operation in power-managed modes .............. 145 baud rate generator (brg) .................................... 145 associated registers ....................................... 146 auto-baud rate detect .................................... 149 baud rate error, calculating ........................... 146 baud rates, asynchronous modes ................. 147 high baud rate select (brgh bit) ................. 145 sampling .......................................................... 145 synchronous master mode ...................................... 158 associated registers, receive ........................ 160 associated registers, transmit ....................... 159 reception ......................................................... 160 transmission ................................................... 158 synchronous slave mode ........................................ 161 associated registers, receive ........................ 162 associated registers, transmit ....................... 161 reception ......................................................... 162 transmission ................................................... 161 extended instruction set addfsr .................................................................. 251 addulnk ................................................................ 251 and using mplab tools .......................................... 257 callw ..................................................................... 252 considerations for use ............................................ 255 movsf .................................................................... 252 movss .................................................................... 253 pushl ..................................................................... 253 subfsr .................................................................. 254 subulnk ................................................................ 254 syntax ...................................................................... 250 external clock input ........................................................... 16 f fail-safe clock monitor ............................................ 184, 198 exiting operation ..................................................... 198 interrupts in power-managed modes ....................... 199 por or wake from sleep ........................................ 199 wdt during oscillator failure ................................. 198 fast register stack ............................................................ 48 firmware instructions ....................................................... 208 flash program memory ..................................................... 65 associated registers ................................................. 73 control registers ....................................................... 66 eecon1 and eecon2 ..................................... 66 tablat (table latch) register ......................... 68 tblptr (table pointer) register ...................... 68 erase sequence ........................................................ 70 erasing ....................................................................... 70 operation during code-protect ................................. 73 reading ...................................................................... 69 table pointer boundaries based on operation ........................ 68 operations with tblrd and tblwt (table) .................................... 68 table pointer boundaries .......................................... 68 table reads and table writes .................................. 65 write sequence ......................................................... 71 writing ....................................................................... 71 protection against spurious writes ................... 73 unexpected termination ................................... 73 write verify ........................................................ 73 fscm. see fail-safe clock monitor. g goto .............................................................................. 229 h hardware multiplier ............................................................ 79 introduction ................................................................ 79 operation ................................................................... 79 performance comparison .......................................... 79 i i/o ports ............................................................................ 81 id locations ............................................................. 184, 203 incf ................................................................................ 229 incfsz ............................................................................ 230 in-circuit debugger .......................................................... 203 in-circuit serial programming (icsp) ...................... 184, 203 independent pwm mode duty cycle assignment ........................................... 131 output ...................................................................... 131 output, channel override ........................................ 132 indexed literal offset addressing and standard pic18 instructions ............................. 255 indexed literal offset mode ............................................. 255 indirect addressing ............................................................ 60 infsnz ............................................................................ 230 initialization conditions for all registers ...................... 41?44 instruction cycle ................................................................ 49 clocking scheme ....................................................... 49 flow/pipelining .......................................................... 49 instruction set .................................................................. 208 addlw .................................................................... 214 addwf ................................................................... 214 addwf (indexed literal offset mode) .................... 256 addwfc ................................................................. 215 andlw .................................................................... 215 andwf ................................................................... 216 bc ............................................................................ 216 bcf ......................................................................... 217 bn ............................................................................ 217 bnc ......................................................................... 218 bnn ......................................................................... 218 bnov ...................................................................... 219 bnz ......................................................................... 219 bov ......................................................................... 222 bra ......................................................................... 220 bsf .......................................................................... 220 bsf (indexed literal offset mode) .......................... 256 btfsc ..................................................................... 221 btfss ..................................................................... 221 btg ......................................................................... 222 bz ............................................................................ 223 call ........................................................................ 223 clrf ....................................................................... 224 clrwdt ................................................................. 224 comf ...................................................................... 225 cpfseq .................................................................. 225 cpfsgt .................................................................. 226
pic18f1230/1330 ds39758b-page 302 advance information ? 2006 microchip technology inc. cpfslt ................................................................... 226 daw ......................................................................... 227 dcfsnz .................................................................. 228 decf ....................................................................... 227 decfsz ................................................................... 228 extended instruction set .......................................... 250 general format ........................................................ 210 goto ...................................................................... 229 incf ......................................................................... 229 incfsz .................................................................... 230 infsnz .................................................................... 230 iorlw ..................................................................... 231 iorwf ..................................................................... 231 lfsr ........................................................................ 232 movf ....................................................................... 232 movff .................................................................... 233 movlb .................................................................... 233 movlw ................................................................... 234 movwf ................................................................... 234 mullw .................................................................... 235 mulwf .................................................................... 235 negf ....................................................................... 236 nop ......................................................................... 236 opcode field descriptions ....................................... 209 pop ......................................................................... 237 push ....................................................................... 237 rcall ..................................................................... 238 reset ..................................................................... 238 retfie .................................................................... 239 retlw .................................................................... 239 return .................................................................. 240 rlcf ........................................................................ 240 rlncf ..................................................................... 241 rrcf ....................................................................... 241 rrncf ..................... ............................................... 242 setf ........................................................................ 242 setf (indexed literal offset mode) ........................ 256 sleep ..................................................................... 243 standard instructions ............................................... 208 subfwb .................................................................. 243 sublw .................................................................... 244 subwf .................................................................... 244 subwfb .................................................................. 245 swapf .................................................................... 245 tblrd ..................................................................... 246 tblwt ..................................................................... 247 tstfsz ................................................................... 248 xorlw .................................................................... 248 xorwf .................................................................... 249 intcon registers ....................................................... 89?91 internal oscillator block ..................................................... 18 adjustment ................................................................. 18 intio modes .............................................................. 18 intosc frequency drift ............................................ 18 intosc output frequency ........................................ 18 osctune register ................................................... 18 pll in intosc modes .............................................. 18 internal rc oscillator use with wdt .......................................................... 195 internet address ............................................................... 307 interrupt sources ............................................................. 184 a/d conversion complete ....................................... 168 intn pin ..................................................................... 99 portb, interrupt-on-change .................................... 99 tmr0 ......................................................................... 99 tmr1 overflow ........................................................ 105 interrupts ............................................................................ 87 interrupts, flag bits interrupt-on-change flag (rbif bit) .......................... 84 intosc, intrc. see internal oscillator block. iorlw ............................................................................. 231 iorwf ............................................................................. 231 ipr registers ..................................................................... 96 l lfsr ................................................................................ 232 low-voltage detect ......................................................... 180 applications ............................................................. 183 associated registers ............................................... 183 characteristics ......................................................... 276 current consumption ............................................... 182 effects of a reset .................................................... 183 operation ................................................................. 181 during sleep .................................................... 183 setup ....................................................................... 182 start-up time ........................................................... 182 typical application ................................................... 183 low-voltage icsp programming. see single-supply icsp programming. lvd. see low-voltage detect. m master clear (mclr ) ......................................................... 35 memory organization ........................................................ 45 data memory ............................................................. 51 program memory ....................................................... 45 memory programming requirements .............................. 274 microchip internet web site ............................................. 307 migration from baseline to enhanced devices ................ 297 migration from high-end to enhanced devices ............... 298 migration from mid-range to enhanced devices ............ 298 movf .............................................................................. 232 movff ............................................................................ 233 movlb ............................................................................ 233 movlw ........................................................................... 234 movsf ............................................................................ 252 movss ............................................................................ 253 movwf ........................................................................... 234 mplab asm30 assembler, linker, librarian .................. 205 mplab icd 2 in-circuit debugger .................................. 206 mplab ice 2000 high-performance universal in-circuit emulator ................................... 206 mplab ice 4000 high-performance universal in-circuit emulator ................................... 206 mplab integrated development environment software ............................................. 204 mplab pm3 device programmer ................................... 206 mplink object linker/mplib object librarian ............... 205 mullw ............................................................................ 235 mulwf ............................................................................ 235
? 2006 microchip technology inc. advance information ds39758b-page 303 pic18f1230/1330 n negf ............................................................................... 236 nop ................................................................................. 236 o oscillator configuration ...................................................... 15 ec .............................................................................. 15 ecio .......................................................................... 15 hs .............................................................................. 15 hspll ........................................................................ 15 internal oscillator block ............................................. 18 intio1 ....................................................................... 15 intio2 ....................................................................... 15 lp ............................................................................... 15 rc .............................................................................. 15 rcio .......................................................................... 15 xt .............................................................................. 15 oscillator selection .......................................................... 184 oscillator start-up timer (ost) ................................... 23, 37 oscillator switching ............................................................ 20 oscillator transitions ......................................................... 21 oscillator, timer1 ............................................................. 105 p packaging ........................................................................ 290 details ...................................................................... 291 marking information ................................................. 290 picstart plus development programmer .................... 207 pie registers ..................................................................... 94 pin functions av dd .......................................................................... 14 av ss .......................................................................... 14 mclr /v pp /ra5/flta ................................................ 11 nc .............................................................................. 14 ra0/an0/int0/kbi0/cmp0 ....................................... 12 ra1/an1/int1/kbi1 .................................................. 12 ra2/tx/ck ................................................................ 12 ra3/rx/dt ................................................................ 12 ra4/t0cki/an2//v ref + ............................................. 12 ra6/osc2/clko/t1oso/t1cki/an3 ...................... 11 ra7/osc1/clki/t1osi/flta ................................... 11 rb0/pwm0 ................................................................ 13 rb1/pwm1 ................................................................ 13 rb2/int2/kbi2/cmp2/t1oso/t1cki ....................... 13 rb3/int3/kbi3/cmp1/t1osi .................................... 13 rb4/pwm2 ................................................................ 13 rb5/pwm3 ................................................................ 13 rb6/pwm4/pgc ....................................................... 13 rb7/pwm5/pgd ....................................................... 13 v dd ............................................................................ 14 v ss ............................................................................. 14 pinout i/o descriptions pic18f1230/1330 ...................................................... 11 pir registers ..................................................................... 92 pll frequency multiplier ................................................... 17 hspll oscillator mode .............................................. 17 use with intosc ....................................................... 17 pop ................................................................................. 237 por. see power-on reset. porta associated registers ................................................. 83 lata register ............................................................ 81 porta register ........................................................ 81 trisa register .......................................................... 81 portb associated registers ................................................. 86 interrupt-on-change flag (rbif bit) ......................... 84 latb register ........................................................... 84 portb register ........................................................ 84 trisb register .......................................................... 84 power control pwm ........................................................ 111 associated registers ............................................... 139 control registers ..................................................... 114 functionality ............................................................ 114 power-managed modes ..................................................... 25 and a/d operation ................................................... 171 clock sources ........................................................... 25 clock transitions and status indicators .................... 26 effects on clock sources .......................................... 23 entering ..................................................................... 25 exiting idle and sleep modes .................................... 31 by interrupt ........................................................ 31 by reset ............................................................ 31 by wdt time-out .............................................. 31 without an oscillator start-up delay ................. 32 idle modes ................................................................. 29 pri_idle .......................................................... 30 rc_idle ........................................................... 31 sec_idle ......................................................... 30 multiple sleep commands ......................................... 26 run modes ................................................................ 26 pri_run ........................................................... 26 rc_run ............................................................ 27 sec_run ......................................................... 26 selecting .................................................................... 25 sleep mode ............................................................... 29 summary (table) ........................................................ 25 power-on reset (por) ...................................................... 35 time-out sequence ................................................... 37 power-up delays ............................................................... 23 power-up timer (pwrt) ................................................... 23 prescaler, timer0 ............................................................ 103 pri_idle mode ................................................................. 30 pri_run mode ................................................................. 26 program counter ............................................................... 46 pcl, pch and pcu registers .................................. 46 pclath and pclatu registers .............................. 46 program memory and extended instruction set .................................... 63 instructions ................................................................ 50 two-word .......................................................... 50 interrupt vector .......................................................... 45 look-up tables .......................................................... 48 map and stack (diagram) .......................................... 45 reset vector .............................................................. 45 program verification ........................................................ 200 programming, device instructions ................................... 208 push ............................................................................... 237 push and pop instructions .............................................. 47 pushl ............................................................................. 253 pwm fault input ................................................................ 136 output and polarity control ..................................... 135 single-pulse operation ............................................ 132 special event trigger .............................................. 138 update lockout ....................................................... 138
pic18f1230/1330 ds39758b-page 304 advance information ? 2006 microchip technology inc. pwm dead time decrementing the counter ....................................... 130 distortion .................................................................. 131 generators ............................................................... 129 insertion ................................................................... 129 ranges ..................................................................... 130 pwm duty cycle .............................................................. 125 center-aligned ......................................................... 127 complementary operation ....................................... 128 edge-aligned ........................................................... 126 register buffers ....................................................... 126 registers .................................................................. 125 pwm output override ...................................................... 132 complementary mode .............................................. 132 examples ................................................................. 134 synchronization ....................................................... 132 pwm period ..................................................................... 123 pwm time base .............................................................. 114 continuous up/down count modes ......................... 119 free-running mode ................................................. 119 interrupts .................................................................. 119 in continuous up/down count mode .............. 120 in double update mode ................................... 122 in free-running mode ..................................... 119 in single-shot mode ........................................ 120 postscaler ................................................................ 119 prescaler .................................................................. 119 single-shot mode .................................................... 119 r ram. see data memory. rbif bit .............................................................................. 84 rc oscillator ...................................................................... 17 rcio oscillator mode ................................................ 17 rc_idle mode .................................................................. 31 rc_run mode .................................................................. 27 rcall .............................................................................. 238 rcon register bit status during initialization .................................... 40 reader response ............................................................ 308 register file summary ................................................. 55?57 registers adcon0 (a/d control 0) ......................................... 164 adcon1 (a/d control 1) ......................................... 165 adcon2 (a/d control 2) ......................................... 166 baudcon (baud rate control) .............................. 144 cmcon (comparator control) ................................ 174 config1h (configuration 1 high) .......................... 185 config2h (configuration 2 high) .......................... 187 config2l (configuration 2 low) ............................ 186 config3h (configuration 3 high) .......................... 189 config3l (configuration 3 low) ............................ 188 config4l (configuration 4 low) ............................ 190 config5h (configuration 5 high) .......................... 191 config5l (configuration 5 low) ............................ 191 config6h (configuration 6 high) .......................... 192 config6l (configuration 6 low) ............................ 192 config7h (configuration 7 high) .......................... 193 config7l (configuration 7 low) ............................ 193 cvrcon (comparator voltage reference control) ........................................... 178 devid1 (device id 1) .............................................. 194 devid2 (device id 2) .............................................. 194 dtcon (dead-time control) .................................. 130 eecon1 (eeprom control 1) ........................... 67, 76 fltconfig (fault configuration) ........................... 137 intcon (interrupt control) ........................................ 89 intcon2 (interrupt control 2) ................................... 90 intcon3 (interrupt control 3) ................................... 91 ipr1 (peripheral interrupt priority 1) ......................... 96 ipr2 (peripheral interrupt priority 2) ......................... 97 ipr3 (peripheral interrupt priority 3) ......................... 97 lvdcon (low-voltage detect control) .................. 180 osccon (oscillator control) .................................... 22 osctune (oscillator tuning) ................................... 19 ovdcond (output override control) ..................... 134 ovdcons (output state) ....................................... 134 pie1 (peripheral interrupt enable 1) .......................... 94 pie2 (peripheral interrupt enable 2) .......................... 95 pie3 (peripheral interrupt enable 3) .......................... 95 pir1 (peripheral interrupt request (flag) 1) ............. 92 pir2 (peripheral interrupt request (flag) 2) ............. 93 pir3 (peripheral interrupt request (flag) 3) ............. 93 ptcon0 (pwm timer control 0) ............................ 116 ptcon1 (pwm timer control 1) ............................ 116 pwmcon0 (pwm control 0) .................................. 117 pwmcon1 (pwm control 1) .................................. 118 rcon (reset control) ......................................... 34, 98 rcsta (receive status and control) ..................... 143 status .................................................................... 58 stkptr (stack pointer) ............................................ 47 t0con (timer0 control) ......................................... 101 t1con (timer1 control) ......................................... 105 txsta (transmit status and control) ..................... 142 wdtcon (watchdog timer control) ...................... 196 reset ............................................................................. 238 reset state of registers .................................................... 40 resets ........................................................................ 33, 184 brown-out reset (bor) ........................................... 184 oscillator start-up timer (ost) ............................... 184 power-on reset (por) ............................................ 184 power-up timer (pwrt) ......................................... 184 retfie ............................................................................ 239 retlw ............................................................................ 239 return .......................................................................... 240 return address stack ........................................................ 46 associated registers ................................................. 46 return stack pointer (stkptr) ........................................ 47 revision history ............................................................... 296 rlcf ............................................................................... 240 rlncf ............................................................................. 241 rrcf ............................................................................... 241 rrncf ........................ .................................................... 242 s sec_idle mode ............................................................... 30 sec_run mode ................................................................ 26 setf ................................................................................ 242 single-supply icsp programming ................................... 203 sleep ............................................................................. 243 sleep osc1 and osc2 pin states ...................................... 23 software simulator (mplab sim) ................................... 205 special features of the cpu ........................................... 184 special function registers map ............................................................................ 54 stack full/underflow resets .............................................. 48 subfsr .......................................................................... 254
? 2006 microchip technology inc. advance information ds39758b-page 305 pic18f1230/1330 subfwb .......................................................................... 243 sublw ............................................................................ 244 subulnk ........................................................................ 254 subwf ............................................................................ 244 subwfb .......................................................................... 245 swapf ............................................................................ 245 t table reads/table writes ................................................. 48 tblrd ............................................................................. 246 tblwt ............................................................................. 247 time-out in various situations (table) ................................ 37 timer0 .............................................................................. 101 16-bit mode timer reads and writes ...................... 103 associated registers ............................................... 103 clock source edge select (t0se bit) ...................... 103 clock source select (t0cs bit) ............................... 103 interrupt .................................................................... 103 operation ................................................................. 103 prescaler .................................................................. 103 switching the assignment ................................ 103 prescaler assignment (psa bit) .............................. 103 prescaler select (t0ps2:t0ps0 bits) ..................... 103 prescaler. see prescaler, timer0. timer1 .............................................................................. 105 16-bit read/write mode ........................................... 108 associated registers ............................................... 109 interrupt .................................................................... 108 operation ................................................................. 106 oscillator .......................................................... 105, 107 oscillator layout considerations ............................. 107 overflow interrupt .................................................... 105 tmr1h register ...................................................... 105 tmr1l register ....................................................... 105 use as a clock source ............................................ 107 use as a real-time clock ....................................... 108 timing diagrams a/d conversion ........................................................ 286 asynchronous reception ......................................... 155 asynchronous transmission .................................... 152 asynchronous transmission (back to back) ........... 152 automatic baud rate calculation ............................ 150 auto-wake-up bit (wue) during normal operation ............................................ 156 auto-wake-up bit (wue) during sleep ................... 156 brg overflow sequence ......................................... 150 brown-out reset (bor) ........................................... 282 clko and i/o .......................................................... 281 clock/instruction cycle .............................................. 49 dead-time insertion for complementary pwm ....... 129 duty cycle update times in continuous up/down count mode ..................................... 126 duty cycle update times in continuous up/down count mode with double updates ... 127 edge-aligned pwm .................................................. 126 eusart synchronous receive (master/slave) ................................................. 284 eusart synchronous transmission (master/slave) ................................................. 284 external clock (all modes except pll) ................... 279 fail-safe clock monitor ............................................ 199 low-voltage detect characteristics ......................... 276 low-voltage detect operation ................................. 182 override bits in complementary mode .................... 133 pwm output override example #1 .......................... 135 pwm output override example #2 .......................... 135 pwm period buffer updates in continuous up/down count modes ................................... 124 pwm period buffer updates in free-running mode ......................................... 124 pwm time base interrupt (free-running mode) ...................................... 120 pwm time base interrupt (single-shot mode) ....... 121 pwm time base interrupts (continuous up/down count mode with double updates) .................. 122 pwm time base interrupts (continuous up/down count mode) .................................... 121 reset, watchdog timer (wdt), oscillator start-up timer (ost), power-up timer (pwrt) ................................................. 282 send break character sequence ............................ 157 slow rise time (mclr tied to v dd , v dd rise > t pwrt ) ............................................ 39 start of center-aligned pwm .................................. 127 synchronous reception (master mode, sren) ..................................... 160 synchronous transmission ..................................... 158 synchronous transmission (through txen) .......... 159 time-out sequence on por w/pll enabled (mclr tied to v dd ) .......................................... 39 time-out sequence on power-up (mclr not tied to v dd , case 1) ...................... 38 time-out sequence on power-up (mclr not tied to v dd , case 2) ...................... 38 time-out sequence on power-up (mclr tied to v dd , v dd rise < t pwrt ) ........... 38 timer0 and timer1 external clock .......................... 283 transition for entry to idle mode ............................... 30 transition for entry to sec_run mode .................... 27 transition for entry to sleep mode ............................ 29 transition for two-speed start-up (intosc to hspll) ........................................ 197 transition for wake from idle to run mode ............... 30 transition for wake from sleep (hspll) .................. 29 transition from rc_run mode to pri_run mode ................................................. 28 transition from sec_run mode to pri_run mode (hspll) .................................. 27 transition to rc_run mode ..................................... 28 timing diagrams and specifications ............................... 279 clko and i/o requirements ................................... 281 eusart synchronous receive requirements .................................................. 284 eusart synchronous transmission requirements .................................................. 284 external clock requirements .................................. 279 pll clock ................................................................ 280 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset requirements ........................................ 282 timer0 and timer1 external clock requirements .................................................. 283 top-of-stack access .......................................................... 46 tstfsz ........................................................................... 248 two-speed start-up ................................................. 184, 197 two-word instructions example cases ......................................................... 50 txsta register brgh bit ................................................................. 145
pic18f1230/1330 ds39758b-page 306 advance information ? 2006 microchip technology inc. v voltage reference specifications .................................... 275 w watchdog timer (wdt) ........................................... 184, 195 associated registers ............................................... 196 control register ....................................................... 195 during oscillator failure .......................................... 198 programming considerations .................................. 195 www address ................................................................. 307 www, on-line support ....................................................... 5 x xorlw ............................................................................ 248 xorwf ............................................................................ 249
? 2006 microchip technology inc. advance information ds39758b-page 307 pic18f1230/1330 the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notification and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com
pic18f1230/1330 ds39758b-page 308 advance information ? 2006 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds39758b pic18f1230/1330 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
pic18f1230/1330 ? 2006 microchip technology inc. advance information ds39758b-page 309 pic18f1230/1330 product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . part no. x /xx xxx pattern package temperature range device device pic18f1230/1330 (1) pic18f1230/1330t (2) v dd range 4.2v to 5.5v pic18lf1230/1330 (1) pic18lf1230/1330t (2) v dd range 2.0v to 5.5v temperature range i = -40 c to +85 c (industrial) e= -40 c to +125 c (extended) package (3) so = plastic small outline (soic) ss = plastic shrink small outline (ssop) p = plastic dual in-line (pdip) ml = plastic quad flat no lead (qfn) pattern qtp, sqtp, code or special requirements (blank otherwise) examples: a) pic18lf1330-i/p 301 = industrial temp., pdip package, extended v dd limits, qtp pattern #301. b) pic18lf1230-i/so = industrial temp., soic package, extended v dd limits. note 1: f = standard voltage range lf = wide voltage range 2: t = in tape and reel qfn packages only
ds39758b-page 310 advance information ? 2006 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta alpharetta, ga tel: 770-640-0034 fax: 770-640-0307 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 san jose mountain view, ca tel: 650-215-1444 fax: 650-961-0286 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8676-6200 fax: 86-28-8676-6599 china - fuzhou tel: 86-591-8750-3506 fax: 86-591-8750-3521 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - shunde tel: 86-757-2839-5507 fax: 86-757-2839-5571 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xian tel: 86-29-8833-7250 fax: 86-29-8833-7256 asia/pacific india - bangalore tel: 91-80-4182-8400 fax: 91-80-4182-8422 india - new delhi tel: 91-11-5160-8631 fax: 91-11-5160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - gumi tel: 82-54-473-4301 fax: 82-54-473-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - penang tel: 60-4-646-8870 fax: 60-4-646-5086 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-572-9526 fax: 886-3-572-6459 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-399 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 02/16/06


▲Up To Search▲   

 
Price & Availability of PIC18F1230-IMLSQTP

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X